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:
Sum of cell array

Subject: Sum of cell array

From: Antonio Valentine

Date: 2 Aug, 2012 06:44:11

Message: 1 of 2

Hello I have less experince in using the cell array before. I need some help.

Here it goes,

I have a cell array "D" like this.
    {29x10 cell} {40x10 cell}
    {37x10 cell} []

Each element
>> D{1,1}{1:10,10} % go for 10 arrays.
ans =
     0 0 0
ans =
     0 0 0
ans =
     0 0 0
ans =
    0 0 0
ans =
     0 3 0
ans =
    0 0 0
ans =
     0 7 0
ans =
     0 0 0
ans =
    0 0 0
ans =
     6 6 6

I want to keep the results to only 1 variable e.g., D_temp{1,1}{1,1} = [6 16 6].

Basically, I want to have a summation along the dimension "c" -- {a,b}{c,d}.

What are the function should I use including all the statiscal functions too.

Thank you in your kindly help

Subject: Sum of cell array

From: Bruno Luong

Date: 2 Aug, 2012 13:32:13

Message: 2 of 2

"Antonio Valentine" <chanloha@gmail.com> wrote in message <jvd7jr$pqc$1@newscl01ah.mathworks.com>...
> Hello I have less experince in using the cell array before. I need some help.
>
> Here it goes,
>
> I have a cell array "D" like this.
> {29x10 cell} {40x10 cell}
> {37x10 cell} []
>
> Each element
> >> D{1,1}{1:10,10} % go for 10 arrays.
> ans =
> 0 0 0
> ans =
> 0 0 0
> ans =
> 0 0 0
> ans =
> 0 0 0
> ans =
> 0 3 0
> ans =
> 0 0 0
> ans =
> 0 7 0
> ans =
> 0 0 0
> ans =
> 0 0 0
> ans =
> 6 6 6
>
> I want to keep the results to only 1 variable e.g., D_temp{1,1}{1,1} = [6 16 6].
>
> Basically, I want to have a summation along the dimension "c" -- {a,b}{c,d}.
>
> What are the function should I use including all the statiscal functions too.

None, you have to convert to numerical ARRAY:

% Sum C
A = cat(1, D{1,1}{1:10,10});
S = sum(A,1)

Or use FOR-LOOP if you stick to CELL.

Bruno

Tags for this Thread

No tags are associated with 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