wait for key press

  • Follow


When looking at a bunch of a figures I tend to plot them in a loop and then use the pause function to allow keying between plots.  Unfortunately if dbstop if error is true, then ctrl+c'ing out of it throws an errror.  I tried catching and ignoring the error but the error couldn't be caught.  I instead tried waitforbuttonpress, but there is no option to limit this to only a mouse or a keyboard input, which means when I start using the mouse on the figure the plotting continues.  

Hopefully the goal is clear, any suggestions or workarounds?  Thanks.
0
Reply Jim 3/3/2010 8:32:05 AM

"Jim Hokanson" <jah104@pitt.com> wrote in message <hml6q5$gnu$1@fred.mathworks.com>...
> When looking at a bunch of a figures I tend to plot them in a loop and then use the pause function to allow keying between plots.  Unfortunately if dbstop if error is true, then ctrl+c'ing out of it throws an errror.  I tried catching and ignoring the error but the error couldn't be caught.  I instead tried waitforbuttonpress, but there is no option to limit this to only a mouse or a keyboard input, which means when I start using the mouse on the figure the plotting continues.  
> 
> Hopefully the goal is clear, any suggestions or workarounds?  Thanks.

See the help of WAITFORBUTTONPRESS.

function WaitForMouseButton
% WaitForMouseButton - Pause until the user clicks a mouse button
% This function uses the current figure, or creates a new figure of none exists.
while waitforbuttonpress ~= 0 ; 
  pause(0.1) ; % allow for ctrl-c
end

hth
Jos
0
Reply Jos 3/3/2010 8:55:21 AM


Thanks Jos,

  I should have clarified on that in my post. That function takes over the mouse listener which means I cannot use the mouse on the figure.  i.e. I click on the figure with the mouse and instead of getting the desired function, such as zooming on a figure, I just run another iteration of the loop.  I'm thinking I might just use get(gcf,'CurrentCharacter') with a try/catch around it in case it is closed (or something like that).

Jim
0
Reply Jim 3/3/2010 5:43:03 PM

"Jim Hokanson" <jah104@pitt.com> wrote in message <hmm737$ser$1@fred.mathworks.com>...
> Thanks Jos,
> 
>   I should have clarified on that in my post. That function takes over the mouse listener which means I cannot use the mouse on the figure.  i.e. I click on the figure with the mouse and instead of getting the desired function, such as zooming on a figure, I just run another iteration of the loop.  I'm thinking I might just use get(gcf,'CurrentCharacter') with a try/catch around it in case it is closed (or something like that).
> 
> Jim


Perhaps you can put  UIWAIT at the end of the iteration and create a button/menu on the figure with UIRESUME as its callback ...

Jos
0
Reply Jos 3/3/2010 6:42:05 PM

3 Replies
1176 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/23/2012 2:47:19 PM


Reply: