How can I generalize this for loop?

My question is easy. How can I generalize this for loop?
-----------------------
for i=1:r
t(1)=(d(1))/total
t(2)=(d(2)+d(1))/total
t(3)=(d(3)+d(2)+d(1))/total
t(4)=(d(4)+d(3)+d(2)+d(1))/total
.
.
.
end
------------------------

 采纳的回答

更多回答(2 个)

Thomas
Thomas 2013-7-12
编辑:Thomas 2013-7-12
a=1:9 % input
for ii=1:9
t(ii)=sum(a(1:ii))/sum(a);
end
t

类别

帮助中心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!

Translated by