how to Sum Array with "for" loop ?
13 次查看(过去 30 天)
显示 更早的评论
need help, how i can get value of c(t)=b(1)+b(2)+...+b(t) in matlab ? e.g. a=0 for t=1:5 b=a+t end
will result b = [1] b = [1 2] b = [1 2 3] b = [1 2 3 4] b = [1 2 3 4 5]
then i want to make
c(1)=b(1) c(2)=b(1)+b(2) ... c(t)=b(1)+b(2)+...+b(t)
1 个评论
Jan
2017-5-26
The question is not clear. "b=[1], b=[1,2]" is not a result, but multiple results assigned to the same variable.
Currently the best answer would be:
c = cumsum(1:5);
But is this really what you are looking for?
更多回答(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!