Break Out of While Loop with ESC key
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I want something like below.
while(see if esc key is pressed)
reading serial port;
writing to another serial port;
end
code;
code;
fclose(serialports);
where the while loop continues to execute until the escape key is pressed. Currently i am doing it with while(1). but when i have to end the program i have to press ctrl+c. Which terminates the program and the code where the ports are to be closed is not executed. So i want to get out of the while loop when escape is pressed and the code below the while loop is also executed.
0 Kommentare
Akzeptierte Antwort
Jan
am 18 Jun. 2012
What about a small GUI?
DlgH = figure;
H = uicontrol('Style', 'PushButton', ...
'String', 'Break', ...
'Callback', 'delete(gcbf)');
while (ishandle(H))
disp(clock);
pause(0.5);
end
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!