Changing Steps in a loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello Guys,
I have a small issue with a loop, which needs to have some kind of dynamic steps.
The context is the following, I am working on a 5 business days, which is normal week. Normally the calculations start on monday which is referenced as 2 in Matlab, but there are weeks where Mondays are bank holidays, so here I have my issues, because a constant step will not help if I do the following :
Heres are the data :
Mon 1416.18 733414
Tue 1390.19 733415
Wed 1409.13 733416
Thu 1420.33 733417
Fri 1401.02 733418
Mon 1416.25 733421
Tue 1380.95 733422
Wed 1373.2 733423
Thu 1333.25 733424
Fri 1325.19 733425
Tue 1310.5 733429
Wed 1338.6 733430
Thu 1352.07 733431
Fri 1330.61 733432
Mon 1353.96 733435
Tue 1362.3 733436
Wed 1355.81 733437
Thu 1378.55 733438
Fri 1395.42 733439
Mon 1380.82 733442
Code
step = 5
for i : 2 : step : n
if DayNumber == 2
calculations when first day is monday
end
if DayNumber == 3 ( tuesday)
do operation
step = step -1
end
end
so here normally, i expected an i of 2,7,12,16( Not 17), then 21( 16+5, back to step 5)
Unfortunately I am getting always a constant step of 5, do you know how to make the loop reactive to the steps.
thanks
Davin
0 commentaires
Réponses (2)
Image Analyst
le 16 Fév 2015
The code doesn't run. The data needs to be a cell array and you didn't do that for us, so I'm not even going to try it. Basically if your loop step/increment/counter needs to vary during each iteration then you can't use a "for" loop - you need to use a "while" loop. Make your variable defined correctly and I might fix it for you.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!