2 Variable increment in one "for Loop'

46 visualizaciones (últimos 30 días)
Anuj Nandal
Anuj Nandal el 15 de Dic. de 2020
Comentada: KSSV el 15 de Dic. de 2020
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.

Respuestas (2)

KSSV
KSSV el 15 de Dic. de 2020
Editada: KSSV el 15 de Dic. de 2020
for i = 1:10
for j = 1:2:20
[i j]
end
end
  5 comentarios
Anuj Nandal
Anuj Nandal el 15 de Dic. de 2020
Editada: KSSV el 15 de Dic. de 2020
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?
KSSV
KSSV el 15 de Dic. de 2020
Thats fine.

Iniciar sesión para comentar.


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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by