Accumulating data in a loop while
3 次查看(过去 30 天)
显示 更早的评论
Good evening, I need to collect data into an array with accumulation.
For example, there are 9 time values t=9, the array should look like this (0 t1 t1+t2 t1+t2+t3 and...) I want to do this in a loop so that it would be possible to regulate the number of t values.
So far I've thought of this, but it doesn't work correctly:
index=1;
n=10;
c=[];
while index<10
t = b(index)+b(index+1)
if t>b(index) && index<10
t1=0;
t1 = t + b(index)
index=index+1;
end
c=[c t1];
end
c
3 个评论
采纳的回答
Voss
2024-1-29
t = rand(1,9) % 9 random t values
c = cumsum([0 t]) % c = [0, t(1), t(1)+t(2), t(1)+t(2)+t(3), etc.]
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!