How to step over a loop and go into next iteration & plot graph with different vector length?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Mahdi
2013-4-3
编辑:Mahdi
2013-4-3
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!