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

2 次查看(过去 30 天)
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

采纳的回答

Alex Mcaulley
Alex Mcaulley 2019-8-5
Being M your matrix:
sol = sum(sum(M,3),2)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by