for loop with exceptions

I wanted to run the loop
for even = 2:2:26
but I don't want to include 4. how do i say this?

Respuestas (2)

Pawel Jastrzebski
Pawel Jastrzebski el 8 de En. de 2018
Editada: Pawel Jastrzebski el 8 de En. de 2018

0 votos

loopCounter = [2,6:2:26]
for i = loopCounter
i
% your code
end
Jan
Jan el 8 de En. de 2018

0 votos

for even = 2:2:26
if even ~= 4
disp(even)
end
end
Or
index = 2:2:26;
index(index == 4) = [];
for k = index
disp(k);
end
Or for a larger list of excluded variables:
index = 2:2:26;
index = setdiff(index, [4,8,18]);
for k = index
disp(k);
end

Categorías

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

Etiquetas

Preguntada:

cgo
el 8 de En. de 2018

Respondida:

Jan
el 8 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by