help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using match to filter cell values


From: Dr. Johannes Zellner
Subject: Re: using match to filter cell values
Date: Sat, 16 Oct 2010 17:59:05 +0200

thanks -- that's exactly what I needed.
--
Johannes


2010/10/16 Junqian Gordon Xu <address@hidden>
On 10/15/2010 03:22 PM, James Sherman Jr. wrote:
> I'm not familiar with match, or how it works, but I think I can offer an
> alternative.  I use the function "cellfun" a lot for what I think you're
> trying to do.  For example, if you say wanted to find all the even
> entries in a cell array,
>
> a = {0, 3, 4, 9, 10};
> indices = cellfun(@x (mod(x,2))==0, a);
                    ^^^ syntax error
> even_entries = a(indices);
>
> cellfun maps each element in the cell array to what the output to the
> function is, and since it is logical output, we can use that to index
> into the cell array to get the even entries.

indices = cellfun(@(x) mod(x,2)==0, a);

Gordon
_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

[Prev in Thread] Current Thread [Next in Thread]