How to repeat something for multiple range of intervals?

2 次查看(过去 30 天)
How do I do this without repeating it multiple times?
for i = 1:359
do something
end
for i = 1+(1440*1):359+(1440*1)
do something
end
for i =1+(1440*2):359+(1440*2)
do something
end
.
.
.
for i =1+(1440*27):359+(1440*27)
do something
end
  4 个评论
Tommy
Tommy 2020-4-20
编辑:Tommy 2020-4-20
Possibly this?
idx = [1:359 1+(1440*1):359+(1440*1) 1+(1440*2):359+(1440*2) 1+(1440*27):359+(1440*27)];
for i = idx
%do something
end
(edit) Ah I completely missed the dots...
Thanathip Boonmee
Thanathip Boonmee 2020-4-20
Thank sir! But I will use Ameer Hamza's answer so I dont have to copy-paste 27 times! Appreciate it anyway!

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-20
编辑:Ameer Hamza 2020-4-20
Extending the method suggested by Tommy, instead of writing each set manually, you can use this
idx = (1:359).' + (0:1440:1440*27);
idx = idx(:);
for i = idx
% do something
end
For versions older then R2016b
idx = bsxfun(@plus, (1:359).', (0:1440:1440*2));
idx = idx(:);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by