Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Index over multiple cell arrays with cellfun

Subject: Index over multiple cell arrays with cellfun

From: Ben

Date: 4 Nov, 2010 16:52:03

Message: 1 of 5

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

Subject: Index over multiple cell arrays with cellfun

From: Sean

Date: 4 Nov, 2010 17:04:04

Message: 2 of 5

"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)

Subject: Index over multiple cell arrays with cellfun

From: Ben

Date: 4 Nov, 2010 17:27:05

Message: 3 of 5

"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.

Subject: Index over multiple cell arrays with cellfun

From: Bruno Luong

Date: 4 Nov, 2010 19:42:03

Message: 4 of 5

 > 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

Subject: Index over multiple cell arrays with cellfun

From: Sean

Date: 4 Nov, 2010 20:30:09

Message: 5 of 5

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us