Where is my mistake on cumulative sum of 4 matrices?

조회 수: 5 (최근 30일)
Volkan Yangin
Volkan Yangin 2017년 3월 19일
댓글: Star Strider 2017년 3월 19일
Hi everbody, I have 4 matrices and to find cumulative sum of them, i use this code:
%aa includes 4 matrices (4 line, 101 columns for each line)
for i=1:1:4;
cum_sum=cumsum(aa(i,:))
end
MATLAB gives me one result with this code. How can i generate 4 result with using this code?
Thanks
  댓글 수: 5
Volkan Yangin
Volkan Yangin 2017년 3월 19일
편집: Volkan Yangin 2017년 3월 19일
Yes. Aa is a single variable. I plan to find cumulative sum of each line of aa.
Writing English is sometimes hard of me. :) Sorry for this.
Star Strider
Star Strider 2017년 3월 19일
No worries.
The code for 4 matrices is much different that for 1 matrix with 4 rows.

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

채택된 답변

the cyclist
the cyclist 2017년 3월 19일
My best guess, with the current information as I write this, is that you just need either
cum_sum = cumsum(aa)
or
cum_sum = cumsum(aa,2)
without using the for loop at all.

추가 답변 (1개)

Star Strider
Star Strider 2017년 3월 19일
If you have one matrix with 4 rows and 101 columns, this works:
cum_sum = cumsum(aa,2);
  댓글 수: 2
Volkan Yangin
Volkan Yangin 2017년 3월 19일
Thanks Star Strider. I have just saved the code you sent.
Star Strider
Star Strider 2017년 3월 19일
My pleasure.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by