help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cell


From: James Sherman Jr.
Subject: Re: cell
Date: Tue, 2 Jun 2009 10:52:06 -0400

If your matrices are all the same size (which I assume is the case since you need to add them), it would probably be better to store them in a 3d array since it will be easier to access them.  In your example, you could do:
A = zeros(10, 10, 10);
A(:, :, 1) = a matrix10x10
A(:, :, 2) = a matrix10x10
...
A(:, :, 10) = a matrix10x10

Then to add them up, all you need to do is:
sum(A, 3)

However, if you want to use cell arrays like you describe, one way to add them up would be:
sum(reshape(cell2mat(A), 10, 10, []), 3)

But that is rather shoehorning it into a 3d array to add them up.  There may be a more direct way to add them besides just doing a for loop.

On Tue, Jun 2, 2009 at 10:05 AM, Carlo Rossi <address@hidden> wrote:

Hello,
 I have a cell
 A = cell(10,1);
A{1} = a matrix10x10
A{2} = a matrix10x10

A{10} = a matrix10x10

Hoping it's a good way to use the cell
now I need to sum up all matrix inside A. is there a compactway to do it? (I need A{1} + A{2} .......)
thanks,





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


reply via email to

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