필터 지우기
필터 지우기

for loop indexing and skip numbers

조회 수: 18 (최근 30일)
Damith
Damith 2014년 5월 28일
댓글: Abraxas 2019년 4월 25일
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.

채택된 답변

Roger Stafford
Roger Stafford 2014년 5월 28일
You can also use
ix = floor((4*(1:n)+2)/3);
where n is the desired length of the output.
  댓글 수: 1
Damith
Damith 2014년 5월 28일
Thanks. I appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

the cyclist
the cyclist 2014년 5월 28일
for n = [2 3 4 6 7 8 13]
disp(n)
end
  댓글 수: 5
Damith
Damith 2014년 5월 28일
Thanks. It worked.
Abraxas
Abraxas 2019년 4월 25일
I've been searching 2 days for this answer! Thank you so much!

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2014년 5월 28일
Yet another method:
idx = bsxfun(@plus,[1 2 3]',1:4:100)
for ii = idx(:)
disp(ii)
end
  댓글 수: 1
Damith
Damith 2014년 5월 28일
Thanks. it's working too.

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2014년 5월 29일
Yet another method:
idx = filter([1 1 1 1],[1 1 1 0],1:100)+1

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by