Can I exit my while loop manually and let the code finish the script after the while loop?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello,
I have some code where I'm in a never ending while loop which I am able to stop manually by pressing ctrl+c of by deleting the figure that opens during the loop. After the loop is some code that opens another figure and plots some values which were calculated in the while loop.
Is there a way where I have the possibility of ending the while loop on my command and still having Matlab finishing the rest of the script after the while loop? It doesn't matter in which part of the while loop it is executed/left.
I'm using Matlab R2015b.
My code looks something like this:
open a figure
while true
Calculate all sorts of magic
drawnow % Apply the newly calculated values on the earlier opened figure
pause(1)
end
open another figure and plot certain values from the loop
댓글 수: 0
답변 (1개)
KSSV
2016년 10월 6일
If you are not specific of where while has to exit, then why to use while in the first place?
To exit while loop, you may put some condition and exit the loop. Eg:
count = 0 ;
while count <100
count = count+1 ;
end
참고 항목
카테고리
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!