Can I exit my while loop manually and let the code finish the script after the while loop?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
KSSV
on 6 Oct 2016
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
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!