run a while loop while excluding some point
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sujit
el 19 de Abr. de 2015
Respondida: Geoff Hayes
el 19 de Abr. de 2015
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 comentarios
Respuesta aceptada
Geoff Hayes
el 19 de Abr. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!