MATLAB Answers

BANI tita

how to find the sum of matrix?

Asked by BANI tita
on 17 Oct 2012

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))




No products are associated with this question.

2 Answers

Answer by Matt J
on 17 Oct 2012
Edited by Matt J
on 17 Oct 2012

I'm assuming your matrices are the slices of a 3D array


If so, just do



yes my matrix dimension is 3, A (:,:, k)

thank you very much

Answer by PG
on 17 Oct 2012

If I understand your question correctly:

sum_of_all_matrices = sum(A)


on 17 Oct 2012

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

thank you very much

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!