for loop with exceptions
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Pawel Jastrzebski
2018-1-8
编辑:Pawel Jastrzebski
2018-1-8
loopCounter = [2,6:2:26]
for i = loopCounter
i
% your code
end
0 个评论
Jan
2018-1-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!