Clear Filters
Clear Filters

Give priority to gui callback over code

15 views (last 30 days)
I'm having some issues right now that I would need to be sorted. Here is the situation :
I need to monitor some data, and I want to do it through an interface. (I used the app designer functions)
I have a main program, and an interface which should display some data from the main running program.
The function to generate the interface is called from the main program so that it can have access to the handles.
In order to disturb the main program as little as possible, I put a "Refresh" button on the interface. The "refresh" callback function is nested in the main program. This function updates all the fields of the interface so that it shows the updated data from the main program.
Since I'm starting with some tests, I did this at first :
while toc < 30
value = toc;
With this first test, the refresh button works, my value is displayed in the interface as expected.
But then, I did this :
while toc < 30
value = toc;
Now, clicking on the button will not trigger any change in the interface. It seems that the callback nevers runs until I terminate the program.
Is there any way I can get that fixed ? I cannot afford to leave this "pause" function since the actual main program is supposed to monitor animal behaviour...

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 25 Jul 2017
the pause allows interruption of the code, so yes, it is needed. You can
  • use a much smaller time like pause(0.001)
  • or use drawnow instead of pause. Drawnow allows interruption but doesn't wait. It's like pause with the smallest waiting value possible
Titus Edelhofer
Titus Edelhofer on 26 Jul 2017
Hi Guillaume, your welcome. Yes, pause(0) has the same effect with the advantage of not watching out for redrawing of any graphics. Therefore it could be indeed faster, thanks for the reminder :)
Walter Roberson
Walter Roberson on 26 Jul 2017
Edited: Walter Roberson on 26 Jul 2017
I do not seem to see any documentation that pause(0) treats the event queue or graphics any differently; says that graphics updates and callbacks keep running
"When an object's Interruptible property is set to 'on', its callback can be interrupted at the next occurrence of one of these commands: drawnow, figure, getframe, waitfor, or pause.
If the running callback contains one of these commands, then MATLAB stops the execution of the running callback and executes the interrupting callback. MATLAB resumes executing the running callback when the interrupting callback completes."
which says nothing about pause(0) being special.

Sign in to comment.

More Answers (0)


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

Community Treasure Hunt

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

Start Hunting!