Find sum of individual matrix of a given array of matrices and store it in a temporary array

2 visualizaciones (últimos 30 días)
Suppose M[l,m,n] an array of m*n matrices of size l, and then required to find sum of individual matix and store it in a temporary array .
eg: l=2 m=3 n=3
M[1,m,n]={{0,1,1},{0,0,0},{1,1,1}}=sum(M[1,m,n])=5
M[2,m,n]={{0,1,1},{0,1,0},{1,1,1}}=sum(M[2,m,n])=6
Finally,
store final sum values of each matrix in to a temporary array.
temp[1,l]={5,6}
That is,
temp[1,1]=5
temp[1,2]=6

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 5 de Ag. de 2019
Being M your matrix:
sol = sum(sum(M,3),2)

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by