How can I get MATLAB to leave a loop when any key is pressed?

Respuestas (1)

José-Luis
José-Luis el 21 de Dic. de 2012
Editada: José-Luis el 21 de Dic. de 2012
This is a bit of a hack, and will probably slow down your code. The idea is to create a figure, and check whether a key has been pressed when the figure is active. Ergo, you need to click on the figure window and press a key while the cursor is over it.
WARNING: The following is an infinite loop. Use ctrl+c to break it if problems arise.
h = figure(1);
forever = 1;
while forever
drawnow
isKeyPressed = ~isempty(get(h,'CurrentCharacter'));
if isKeyPressed
break
end
end

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Dic. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by