samer@4: function Y=cellfilt(fn,X) samer@4: % cellfilt - Filter cell array with boolean test samer@4: % samer@4: % cellfilt :: (A->bool), {[N]->A} -> {[M]->A}. samer@4: % cellfilt :: (A->bool), {[1,N]->A} -> {[1,M]->A}. samer@4: % samer@4: % eg, cellfilt(@iseven,{1,2,3,4}) = {2,4} samer@4: samer@4: % SA 2008-06-27 - Now returns cell array with same orientation as input samer@4: samer@4: Y={}; samer@4: [X,E]=shiftdim(X); samer@4: for i=1:numel(X) samer@4: if fn(X{i}), Y=vertcat(Y,X(i)); end samer@4: end samer@4: Y=shiftdim(Y,E);