Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Interrupting a callback.

Subject: Interrupting a callback.

From: Andreas Werner Paulsen

Date: 21 May, 1998 20:33:44

Message: 1 of 2

Hello!
I am making a GUI where pushing a "Play" button starts an infinite loop.
I want this loop to halt if the user pushes the "Pause" button.
How can this be accomplished?

Thanks a lot in advance for any answers!
Andreas

Subject: Interrupting a callback.

From: daf@mathworks.com (David Foti)

Date: 22 May, 1998 17:51:42

Message: 2 of 2

Andreas Werner Paulsen (awpauls@bvemx.ppco.comSPAMNOTHANKS) wrote:
: I am making a GUI where pushing a "Play" button starts an infinite loop.
: I want this loop to halt if the user pushes the "Pause" button.
: How can this be accomplished?

There are a few ways to proceed. Here is one of them:
1) In your function which implements the infinite loop, declare a
global variable which will indicate whether or not to continue the
loop. Make sure that the command "drawnow" is executed in your loop.

2) Make sure that the 'interruptible' property of the "Play" button
is set to the 'on' value.

3) Have your 'Pause' button callback set the value of the global
variable to indicate that the loop should end.

This works because, "interruptible" uicontrols can have their
callbacks interrupted by other callbacks whenever they execute a
drawnow command.

Instead of using a global variable, you could also store a variable in the
'UserData' property of some object which is accessible to both the
'Play' button and the 'Pause' button.

If any of this is unclear, feel free to email me for clarification.
Hope this helps,
-Dave
-----------------------------------------------------
Dave Foti daf@mathworks.com
The MathWorks, Inc.
24 Prime Park Way
Natick, MA 01760 http://www.mathworks.com
-----------------------------------------------------

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us