For loop comand use
1 次查看(过去 30 天)
显示 更早的评论
Hi,I want to compute the sum 2 + 4 + 6 + 8 + 10 + : : : + 100 by using For loop . Can anyone here thankfully help me out?
4 个评论
James Tursa
2017-10-5
编辑:James Tursa
2017-10-5
Change
total = total + 1;
to
total = total + k; % <-- You need to add the index variable k, not 1 every time
采纳的回答
James Tursa
2017-10-5
The general outline of your for loop would be:
total = 0;
for k=start_value:increment:end_value % <-- you fill in the start_value, increment, and end_value
total = total + something; % <-- you fill in the something
end
0 个评论
更多回答(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!