Where is my mistake on cumulative sum of 4 matrices?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2017-3-19
No worries.
The code for 4 matrices is much different that for 1 matrix with 4 rows.
采纳的回答
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
2017-3-19
If you have one matrix with 4 rows and 101 columns, this works:
cum_sum = cumsum(aa,2);
另请参阅
类别
在 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!