for loop indexing and skip numbers
Ältere Kommentare anzeigen
Hi,
I need to include for loop in MATLAB to start with 2:13. But I need to start with 2,3,4 and skip 5 and again 6,7,8 and skip 9 and 10,11,12 until 13.
How can I implement this is for loop?
Many thanks in advance.
Akzeptierte Antwort
Weitere Antworten (3)
the cyclist
am 28 Mai 2014
for n = [2 3 4 6 7 8 13]
disp(n)
end
5 Kommentare
Damith
am 28 Mai 2014
Image Analyst
am 28 Mai 2014
Bearbeitet: Image Analyst
am 28 Mai 2014
A nice feature that not many people know about, but more should. It's good that you pointed it out. +1 vote.
the cyclist
am 28 Mai 2014
idx = setdiff(2:10000,5:4:10000);
for ii = idx
disp(ii)
end
Damith
am 28 Mai 2014
Abraxas
am 25 Apr. 2019
I've been searching 2 days for this answer! Thank you so much!
the cyclist
am 28 Mai 2014
Yet another method:
idx = bsxfun(@plus,[1 2 3]',1:4:100)
for ii = idx(:)
disp(ii)
end
1 Kommentar
Damith
am 28 Mai 2014
the cyclist
am 29 Mai 2014
Yet another method:
idx = filter([1 1 1 1],[1 1 1 0],1:100)+1
1 Kommentar
Damith
am 29 Mai 2014
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!