How to write a for loop?
17 次查看(过去 30 天)
显示 更早的评论
I know the value for all the (10 values) udotreal, and I also know the value of uk for the first iteration. So How do I write a for loop for doing this:
uk1 = uk + udotreal(1,1);
uk2 = uk1 + udotreal(1,2);
uk3 = uk2 + udotreal(1,3);
uk4 = uk3 + udotreal(1,4);
uk5 = uk4 + udotreal(1,5);
uk6 = uk5 + udotreal(1,6);
uk7 = uk6 + udotreal(1,7);
uk8 = uk7 + udotreal(1,8);
uk9 = uk8 + udotreal(1,9);
uk10 = uk9 + udotreal(1,10);
采纳的回答
KSSV
2017-10-27
ukn = zeros(1,10) ;
for i = 1:10
if i == 1
ukn(i) = uk+udotreal(i,i) ;
else
ukn(i) = ukn(i-1)+udotreal(i,i) ;
end
end
0 个评论
更多回答(2 个)
Bishwajit Roy
2020-10-28
ukn = zeros(1,10) ;
for i = 1:10
if i == 1
ukn(i) = uk+udotreal(i,i) ;
else
ukn(i) = ukn(i-1)+udotreal(i,i) ;
end
end
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!