How to repeat something for multiple range of intervals?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Thanathip Boonmee
il 20 Apr 2020
Commentato: Thanathip Boonmee
il 20 Apr 2020
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
Risposta accettata
Ameer Hamza
il 20 Apr 2020
Modificato: Ameer Hamza
il 20 Apr 2020
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(:);
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!