Need help with for loop

hi. i'm trying something simple but i lilterally don't get it why it doesn't works in MATLAB. (i'm not familiar with using MATLAB, but C/C++)
so, here's my code :
for i = 1 : n-4
for j = j+1 : n-4
for k = j+1 : n-4
for l = k+1 : n-4
%% other codes
end
end
end
end
i've try to excute the code above, but the second for loop didn't excute. (it just slipped away)
i know it works on C/C++ or Python. so, what did i missed?
is it because MATLAB wouldn't allow this kind of for loops or something else?

3 comentarios

Torsten
Torsten el 20 de Mayo de 2022
The setting
for j = j+1 : n-4
makes no sense.
Maybe you mean
for j = i+1 : n-4
?
준상 정
준상 정 el 21 de Mayo de 2022
yes i was meant
for j = i+1 : n-4
but it doesn't work either.
Torsten
Torsten el 22 de Mayo de 2022
Then the error lies in the part "other codes".

Iniciar sesión para comentar.

Respuestas (1)

jedak
jedak el 20 de Mayo de 2022

0 votos

Where you define you variable j?
If you define a loop as:
for j=a:b
(code)
end
a should be <= b
if not the loop is not going to work.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Mayo de 2022

Comentada:

el 22 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by