MATLAB,如何在for循环中更改循环索引 [英] MATLAB, how to change loop index inside for loops
本文介绍了MATLAB,如何在for循环中更改循环索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个循环:
b = 1;
for c = 1 : 10;
if b == 1
c = 1 + 3
end
end
要更改 c
,我需要做什么?因为当我通读帮助时,MATLAB在到达 end
结束后重置了循环计数器 c
.
What do I need to do to make to change c
?
Because as I read through the help, MATLAB resets the loop counter c
after it reaches end
.
是否可以在 for
循环中更改循环计数器的值?
Is there any way to change the value of the loop counter from within a for
loop?
推荐答案
您可以使用while循环代替for循环.
you could use a while loop instead of a for loop.
类似的东西(我猜您想在c上加3,否则c = 4可以替换下面的那一行)
something like (I'm guessing you want to add 3 to c otherwise c = 4 could replace that line below)
b = 1;
c = 1;
while(c < 10)
if b == 1
c = c + 3
end
end
这篇关于MATLAB,如何在for循环中更改循环索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文