Mercurial > hg > ishara
diff general/cellutils/cellfilt.m @ 4:e44f49929e56
Adding reorganised general toolbox, now in several subdirectories.
author | samer |
---|---|
date | Sat, 12 Jan 2013 19:21:22 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/general/cellutils/cellfilt.m Sat Jan 12 19:21:22 2013 +0000 @@ -0,0 +1,16 @@ +function Y=cellfilt(fn,X) +% cellfilt - Filter cell array with boolean test +% +% cellfilt :: (A->bool), {[N]->A} -> {[M]->A}. +% cellfilt :: (A->bool), {[1,N]->A} -> {[1,M]->A}. +% +% eg, cellfilt(@iseven,{1,2,3,4}) = {2,4} + +% SA 2008-06-27 - Now returns cell array with same orientation as input + +Y={}; +[X,E]=shiftdim(X); +for i=1:numel(X) + if fn(X{i}), Y=vertcat(Y,X(i)); end +end +Y=shiftdim(Y,E);