for loop with exceptions
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wanted to run the loop
for even = 2:2:26
but I don't want to include 4. how do i say this?
0 Kommentare
Antworten (2)
Pawel Jastrzebski
am 8 Jan. 2018
Bearbeitet: Pawel Jastrzebski
am 8 Jan. 2018
loopCounter = [2,6:2:26]
for i = loopCounter
i
% your code
end
0 Kommentare
Jan
am 8 Jan. 2018
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!