If a Matlab function returns a variable number of values, how can I get all of them as a cellarray,

Posted by kaleidomedallion on Stack Overflow See other posts from Stack Overflow or by kaleidomedallion
Published on 2010-05-12T18:24:47Z Indexed on 2010/05/12 19:24 UTC
Read the original article Hit count: 187

Filed under:
|

I am writing a function to remove some values from a cellarray, like so:

function left = remove(cells, item);
left = cells{cellfun(@(i) ~isequal(item, i), cells)};

But when I run this, left has only the first value, as the call to cells{} with a logical array returns all of the matching cells as separate values. How do I group these separate return values into a single cellarray?

Also, perhaps there is already a way to remove a given item from a cellarray? I could not find it in the documentation.

© Stack Overflow or respective owner

Related posts about matlab

Related posts about functions