for loop indexing and skip numbers

22 次查看(过去 30 天)
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.

更多回答(3 个)

the cyclist
the cyclist 2014-5-28
for n = [2 3 4 6 7 8 13]
disp(n)
end
  5 个评论
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

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