how to find the sum of matrix?

5 次查看(过去 30 天)
BANI tita
BANI tita 2012-10-17
hello, I have a loop as results of K = 1:19, a matrix A (k), my question is how to find the sum (M )of all matrix for each value of k, ie: find M = sum(A (k))

回答(2 个)

Matt J
Matt J 2012-10-17
编辑:Matt J 2012-10-17
I'm assuming your matrices are the slices of a 3D array
M=A(:,:,k)
If so, just do
sum(A,3);

Sachin Ganjare
Sachin Ganjare 2012-10-17
If I understand your question correctly:
sum_of_all_matrices = sum(A)
  2 个评论
Sachin Ganjare
Sachin Ganjare 2012-10-17
For Example:
a1 = [1 2 3]; a2 = [1 2 3]; a3 = [1 2 3]; a123 = [a1 a2 a3]; sum_out = sum(a123);
sum_out is sum of elements of matrix

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by