How can I sum a matrix in a For Loop?

1 Ansicht (letzte 30 Tage)
Edoardo
Edoardo am 2 Nov. 2012
Hi;
I've a model done with matlab in wich I've several for loop, every step of every cycle creates a matrix. I want to sum every created matrix.
thanks

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 2 Nov. 2012
  2 Kommentare
Edoardo
Edoardo am 2 Nov. 2012
I have this:
for t=0;1.:30
CODE OF Model
end
The result of the code is C (matrix 1000x1000).
I would like "Ctotal" to be the sum of C(t=1)+C(t=2).....C(t=30).
Thanks.
PS: I'm Italian what is "doc sum"?
Sean de Wolski
Sean de Wolski am 2 Nov. 2012
sum(C(1:30))
If you evaluate at the MATLAB command line:
>>doc sum
It will tell you all about summing.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 2 Nov. 2012
eg
res=0
for k=1:5
M=rand(4);
res=bsxfun(@plus,res,M)
end
  1 Kommentar
Edoardo
Edoardo am 2 Nov. 2012
I have this:
for t=0;1.:30
CODE OF Model
end
The result of the code is C (matrix 1000x1000).
I would like "Ctotal" to be the sum of C(t=1)+C(t=2).....C(t=30).
Thanks.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by