cell
James Sherman Jr.
shermanj at umd.edu
Tue Jun 2 09:52:06 CDT 2009
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 <serosole at yahoo.it> 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
> Help-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090602/085ff6a9/attachment-0001.html
More information about the Help-octave
mailing list