for loop indexing and skip numbers
이전 댓글 표시
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.
채택된 답변
추가 답변 (3개)
the cyclist
2014년 5월 28일
for n = [2 3 4 6 7 8 13]
disp(n)
end
댓글 수: 5
Damith
2014년 5월 28일
Image Analyst
2014년 5월 28일
편집: Image Analyst
2014년 5월 28일
A nice feature that not many people know about, but more should. It's good that you pointed it out. +1 vote.
the cyclist
2014년 5월 28일
idx = setdiff(2:10000,5:4:10000);
for ii = idx
disp(ii)
end
Damith
2014년 5월 28일
Abraxas
2019년 4월 25일
I've been searching 2 days for this answer! Thank you so much!
the cyclist
2014년 5월 28일
Yet another method:
idx = bsxfun(@plus,[1 2 3]',1:4:100)
for ii = idx(:)
disp(ii)
end
카테고리
도움말 센터 및 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!