필터 지우기
필터 지우기

How to repeat something for multiple range of intervals?

조회 수: 4 (최근 30일)
Thanathip Boonmee
Thanathip Boonmee 2020년 4월 20일
댓글: Thanathip Boonmee 2020년 4월 20일
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에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by