2 Variable increment in one "for Loop'

24 次查看(过去 30 天)
Anuj Nandal
Anuj Nandal 2020-12-15
评论: KSSV 2020-12-15
I was using a code and i need to write one "for loop" with two variable incrementing simultaneously. There is easy code in C, C++, but i'm not able to find one for this one. For reference i want to do this in matlab:
for(i=1,j=2;i<10,j<20;i++,j+2)
I can't use nested loop , could someone please help with this.

回答(2 个)

KSSV
KSSV 2020-12-15
编辑:KSSV 2020-12-15
for i = 1:10
for j = 1:2:20
[i j]
end
end
  5 个评论
Anuj Nandal
Anuj Nandal 2020-12-15
编辑:KSSV 2020-12-15
Thanks for the help, but i think i got it:
j=2
if j<20
for i=1:10
% operation using i,j
j=j+2;
end
end
Is this right?

请先登录,再进行评论。


SHIVAM KUMAR
SHIVAM KUMAR 2020-12-15
Or use j= 2*i
for i=1:9 %the end term will also come so use 9 here.
j=2*i;
%function
end

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by