How to step over a loop and go into next iteration & plot graph with different vector length?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a case which is something like this:
Let's say I have a variable X(i), in a while loop which increases in the multiple of 0.01, means that it's 0.01*i.
For each iteration i, I should be getting a value Y(i) at the end of the iteration.
However, for some of the values X(i), it's not possible in obtaining a value Y(i). So i'd like to step over and go into the next iteration, which is i+1. May I know how do I do that?
Also, at the end of the while loop, i'll need to plot a graph of Y vs X. But because i'm stepping over some X values, which means I'm not getting any values for Y, in the end i'll be getting X and Y of different vector length. In this case, I couldnt get a plot of the graph.
Any ideas how do i do this?
Sorry i couldnt post the code here because it is kind of long.
Hope anyone out there can help me with this.
Thanks
0 commentaires
Réponses (1)
Mahdi
le 3 Avr 2013
Modifié(e) : Mahdi
le 3 Avr 2013
A simple example would be:
X=[1 2 3 4 5 6 7 8 9]
for s=1:10
if ... % If you can evaluate y
Y(s)=s
else % If you can't evaluate it
X(s)=[] % Removes the value from the x matrix
continue
end
end
Just a simple example to see how the continue command works
for s=1:10
if s==8
continue
end
i
end
In the above example, we told the loop that if we reach the number 8, then just go back to the beginning of the loop. Running it will show i from 1 to 10, while skipping 8.
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!