Why does MATLAB produce an error when I execute WAITFORBUTTONPRESS and close the figure window without clicking on the figure?

7 views (last 30 days)
I am using the WAITFORBUTTONPRESS function to block caller input until a mouse click is detected or a key is pressed.
While MATLAB is waiting for a button press, if I close the figure window by clicking on the close icon at the top-right corner of the window, MATLAB throws the following error:
??? Error using ==> waitforbuttonpress
waitforbuttonpress exit because all figures have been deleted
This is not documented in the help page for WAITFORBUTTONPRESS.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Jan 2010
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
This is an error in the documentation for MATLAB 7.7 (R2008b) within the WAITFORBUTTONPRESS section. The documentation should read as follows:
You can interrupt WAITFORBUTTONPRESS by typing Ctrl+C, but an error
results unless the function is called from within a try-catch block.
WAITFORBUTTONPRESS also returns an error if you close the
figure by clicking the X(close) button unless you call WAITFORBUTTONPRESS within a try-catch block.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!