How to exclude unwanted numbers in a cell?

6 views (last 30 days)
M G
M G on 11 Nov 2011
Hey MATLAB users,
I've got a problem! If we have: a={1,17951,1,0 ; 1,20345,1,0 ; 1,22950,1,0 ; 1,25360,1,0};
and I want to exclude 1,...,1,0 which are the same in all and as a result have cell array b as b = {17951 ; 20345 ; 22950 ; 25360}; how can I do that?
Thank you so much for your hint in advance.
Mehdi :)

Accepted Answer

Wayne King
Wayne King on 11 Nov 2011
a={1,17951,1,0 ; 1,20345,1,0 ; 1,22950,1,0 ; 1,25360,1,0};
b = cellfun(@(x) x(x>1),a,'uni',0);
b(cellfun(@isempty,b))=[];
  2 Comments
M G
M G on 11 Nov 2011
Yes, they are always the same values. Thanks a lot.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!