필터 지우기
필터 지우기

How can I sum a matrix in a For Loop?

조회 수: 1 (최근 30일)
Edoardo
Edoardo 2012년 11월 2일
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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 11월 2일
  댓글 수: 2
Edoardo
Edoardo 2012년 11월 2일
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 2012년 11월 2일
sum(C(1:30))
If you evaluate at the MATLAB command line:
>>doc sum
It will tell you all about summing.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 2일
eg
res=0
for k=1:5
M=rand(4);
res=bsxfun(@plus,res,M)
end
  댓글 수: 1
Edoardo
Edoardo 2012년 11월 2일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by