matlab - Summation of matrices -


I want to add each cell to the same position for each matrix. I (i, j, k) stored in MATLAB (i, j) is the amount of matrix and I want to create a matrix which is the sum of all of them - however, the MATLAB command adds each value to each column while I want to add each cell together in the same position from each matrix.

  1 3 4 3 4 0 2 4 4 0 3 1 2 7 8 0 3 1 0 0 0 1 2 1 2 3  

I use the matrix Want to create:

  1 + 3 + 2 + 3 + 4 + 4 + 4 + 0 + 4 + 2 + 1 + 3 + 7 + 3 + 1 + 8 + 9 + 0 + 1 0 + 1 + 2 + 2 + 3  

=

  6 11 8 3 13 10 10 3 7   

Use the second input to specify the dimension with which to sum (in your case, 3):

  & gt; & Gt; A (:,:,, 1) = [1 3 4 3 3 9 2]; & Gt; & Gt; A (:,:,, 2) = [3 4 0 2 7 8 0 1 2]; & Gt; & Gt; A (:,:,, 3) = [2 4 4 3 3 1 1 2 3]; & Gt; & Gt; Zodiac (A, 3) ans = 6 11 8 2 13 10 10 3 7  

Comments