Got Questions? Get Answers.
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:
Summing 2 Cell Arrays

Subject: Summing 2 Cell Arrays

From: Anthony Hopf

Date: 29 Aug, 2010 19:32:03

Message: 1 of 3

I hope this is a simple question to answer. But I have a cell array NxK made up of Mx1 vectors of varying length. I would like to update the cell array by adding another NxK cell array containing Mx1 vectors of the same varying lengths to it, then, in this case, dividing by 2 over the cell array to get the means in each vector. Can this be done?

pseudo code:

for i = 1:W
       %do some stuff
       NKcell = {stuff I did, Mx1 vectors}% put results of varying vector lengths in NKcell array
      NKcellnew = NKcellold +NKcell;
end
NKcellnew./W; %to get mean

Thanks for the help

Subject: Summing 2 Cell Arrays

From: kinor

Date: 30 Aug, 2010 07:52:04

Message: 2 of 3

"Anthony Hopf" <anthony.hopf@gmail.com> wrote in message <i5ecjj$qkm$1@fred.mathworks.com>...
> I hope this is a simple question to answer. But I have a cell array NxK made up of Mx1 vectors of varying length. I would like to update the cell array by adding another NxK cell array containing Mx1 vectors of the same varying lengths to it, then, in this case, dividing by 2 over the cell array to get the means in each vector. Can this be done?
>
> pseudo code:
>
> for i = 1:W
> %do some stuff
> NKcell = {stuff I did, Mx1 vectors}% put results of varying vector lengths in NKcell array
> NKcellnew = NKcellold +NKcell;
> end
> NKcellnew./W; %to get mean
>
> Thanks for the help

Hi,


celarray_lmean = cellfun(@(C,D) (C+D)/2, cellarray1, cellarray1, 'UniformOutput', false)

hth
kinor

Subject: Summing 2 Cell Arrays

From: Anthony Hopf

Date: 30 Aug, 2010 13:48:04

Message: 3 of 3

"kinor " <kinor.removethiswithdot@gmx.de> wrote in message <i5fnv4$ohi$1@fred.mathworks.com>...
> "Anthony Hopf" <anthony.hopf@gmail.com> wrote in message <i5ecjj$qkm$1@fred.mathworks.com>...
> > I hope this is a simple question to answer. But I have a cell array NxK made up of Mx1 vectors of varying length. I would like to update the cell array by adding another NxK cell array containing Mx1 vectors of the same varying lengths to it, then, in this case, dividing by 2 over the cell array to get the means in each vector. Can this be done?
> >
> > pseudo code:
> >
> > for i = 1:W
> > %do some stuff
> > NKcell = {stuff I did, Mx1 vectors}% put results of varying vector lengths in NKcell array
> > NKcellnew = NKcellold +NKcell;
> > end
> > NKcellnew./W; %to get mean
> >
> > Thanks for the help
>
> Hi,
>
>
> celarray_lmean = cellfun(@(C,D) (C+D)/2, cellarray1, cellarray1, 'UniformOutput', false)
>
> hth
> kinor

Kinor

Thank you very much for the reply. I've never played with this syntax, cellfun or arrayfun.

T

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