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: James Sherman Jr.
Subject: Re: using match to filter cell values
Date: Fri, 15 Oct 2010 16:22:34 -0400

On Fri, Oct 15, 2010 at 3:46 PM, Dr. Johannes Zellner <address@hidden> wrote:
Hi,

how can I use match() to filter cell values, eg.

match(@(x) <condition>, {1, 2, 3})

-- 
Johannes

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


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);
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.

Hope this helps.


reply via email to

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