Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 MATLAB(或更一般地)中,如果我只想发生某些事情,例如,每 50 次迭代,for loop我怎么能比下面做得更好?那就是不要写出+50的所有可能值。谢谢。
for loop
for i = 1:1060; if i = 50 || 100 || 150 || ... || 1050 randi(i); % for example, just do something end; end;
你想要的是
if mod(i, 50) == 0 do something
for i = 0:50:1050 do_stuff(i); end
除非,从您的问题中不清楚,如果先前的答案是您真正想要的,在这种情况下您可能需要它
for i = 1:1060 if mod(i, 50) == 0 do_something(i) end do_something_else(i) end
干杯, -