How to step over a loop and go into next iteration & plot graph with different vector length?
조회 수: 3 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!