run a while loop while excluding some point
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
This is a pretty basic but silly doubt i have.
Suppose, i have a while loop in my code, something like this:
f=1;
while f<365
% some functions with variable f.
f=f+1;
end;
So, ideally the while loop will run for values of variable 'f' from 1 to 365.
Now, i don't want to run the loop for variable values f= 15,16,17,300,...(some 65 values).
How can i employ this in my code?
Thanks.
0 Commenti
Risposta accettata
Geoff Hayes
il 19 Apr 2015
Sujit - create an array of those values of f that you wish to ignore and then use that array in your while loop to decide whether to rvalue the functions for f. For example,
ignoreVals = [15 16 17 300];
f = 1;
while f < 365
if ~ismember(f, ignoreVals)
% some functions with variable f
end
f = f + 1;
end
In the above code, we use the ismember function to determine whether f is a member of the array of values that we wish to ignore. If not, then we evaluate some functions for that f.
Try the above and see what happens!
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!