How can I sum a matrix in a For Loop?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi;
I've this code:
for t=0:10 stream=[2 3 4 5 4 5 6 7]; U=stream(randi(length(stream))); y=[1 2 3 4; ... 2 3 4 5 ; ... 1 2 3 4; ... 1 2 3 4; ... 3 4 5 6]; z=U.*y; z=bsxfun(@plus,z,z) t=0:10; end
I would like have a Ztot = z(when t=1)+ z(when t=2)... z(when t=10). I want a single array made from the sums of all the matrices that arise at each step.
Thanks... Edoardo
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2012년 11월 2일
z=0;
stream=[2 3 4 5 4 5 6 7];
y=[1 2 3 4; 2 3 4 5 ; 1 2 3 4;1 2 3 4; 3 4 5 6];
for t=0:10
U=stream(randi(length(stream)));
z=bsxfun(@plus,z,U.*y)
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!