From: Simon Preston on 9 Apr 2010 09:08 Hi, Can somebody please suggest a way to do the following. I would like to be able to exit a loop prematurely by pressing a key on the keyboard. E.g. for the following function I would like to press, say, "q" to break the loop so the function returns foo and k however far it's got through the loop. function [foo,k] = myFunc() foo = 0; for k = 1:1e10 foo = foo + randn; % [break/return here upon user input] end Do I need to use callbacks? I came across this tutorial: http://blinkdagger.com/matlab/matlab-gui-tutorial-adding-keyboard-shortcuts-hotkeys-to-a-gui/2/ for doing similar in a GUI, but I'm still not clear what the simplest solution is. Thanks for any help, S
From: Simon Preston on 19 Apr 2010 13:00 "Simon Preston" <preston.simon+mathsworks(a)gmail.com> wrote in message <hpn8s5$27j$1(a)fred.mathworks.com>... > Hi, > > Can somebody please suggest a way to do the following. I would like to be able to exit a loop prematurely by pressing a key on the keyboard. E.g. for the following function I would like to press, say, "q" to break the loop so the function returns foo and k however far it's got through the loop. > > function [foo,k] = myFunc() > foo = 0; > for k = 1:1e10 > foo = foo + randn; > % [break/return here upon user input] > end > > Do I need to use callbacks? I came across this tutorial: http://blinkdagger.com/matlab/matlab-gui-tutorial-adding-keyboard-shortcuts-hotkeys-to-a-gui/2/ for doing similar in a GUI, but I'm still not clear what the simplest solution is. > > Thanks for any help, S Can anybody suggest anything for this question? Thanks, S
From: Walter Roberson on 19 Apr 2010 13:24 Simon Preston wrote: > "Simon Preston" <preston.simon+mathsworks(a)gmail.com> wrote in message > <hpn8s5$27j$1(a)fred.mathworks.com>... >> Can somebody please suggest a way to do the following. I would like >> to be able to exit a loop prematurely by pressing a key on the >> keyboard. Check out the Matlab File Exchange; it has some relevant user-contributed utilities.
|
Pages: 1 Prev: circle detection and read time Next: Convert to Real Time |