Index over multiple cell arrays with cellfun

  • Follow


Is it possible to index over multiple cell arrays with cellfun?  For example, I have two cell arrays of the same size C and D.  I would like perform an operation that uses a cell from each array.

Ben
0
Reply Ben 11/4/2010 4:52:03 PM

"Ben " <benjamin.terry@colorado.edu> wrote in message <iauobj$m1n$1@fred.mathworks.com>...
> Is it possible to index over multiple cell arrays with cellfun?  For example, I have two cell arrays of the same size C and D.  I would like perform an operation that uses a cell from each array.
> 
> Ben

Yes, just feed them into cellfun

cellfun(@(x,y)x+y,Cell1,Cell2);  %if you need it for your function: ,'uni', false)
0
Reply Sean 11/4/2010 5:04:04 PM


"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iaup24$8q0$1@fred.mathworks.com>...
> "Ben " <benjamin.terry@colorado.edu> wrote in message <iauobj$m1n$1@fred.mathworks.com>...
> > Is it possible to index over multiple cell arrays with cellfun?  For example, I have two cell arrays of the same size C and D.  I would like perform an operation that uses a cell from each array.
> > 
> > Ben
> 
> Yes, just feed them into cellfun
> 
> cellfun(@(x,y)x+y,Cell1,Cell2);  %if you need it for your function: ,'uni', false)

Excellent!  Thank you.
0
Reply Ben 11/4/2010 5:27:05 PM

 > cellfun(@(x,y)x+y,Cell1,Cell2);  %if you need it for your function: ,'uni', false)

or slightly more compact:
> cellfun(@plus, Cell1,Cell2);

Bruno
0
Reply Bruno 11/4/2010 7:42:03 PM

>  > cellfun(@(x,y)x+y,Cell1,Cell2);  %if you need it for your function: ,'uni', false)
> 
> or slightly more compact:
> > cellfun(@plus, Cell1,Cell2);

I was just trying to demonstrate how it would take in two different cells.  The OP didn't ask for the operation between them.
0
Reply Sean 11/4/2010 8:30:09 PM

4 Replies
493 Views

(page loaded in 0.022 seconds)

Similiar Articles:













7/24/2012 4:47:00 AM


Reply: