MATLAB Answers

Give priority to gui callback over code

21 views (last 30 days)
Hi,
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 :
tic;
while toc < 30
value = toc;
pause(1);
end
With this first test, the refresh button works, my value is displayed in the interface as expected.
But then, I did this :
tic;
while toc < 30
value = toc;
end
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...

  0 Comments

Sign in to comment.

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 25 Jul 2017
Hi,
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

  5 Comments

Show 2 older comments
Guillaume Penderia
Guillaume Penderia on 25 Jul 2017
Little update, I just tried to use "pause(0)" as a total shot in the dark, and if I trust the tic/toc functions, it lasts 0.000006 on my setup, which is smaller than the drawnow.
As a staff member, I thought you could be interested.
Thanks again, have a nice day !
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
I do not seem to see any documentation that pause(0) treats the event queue or graphics any differently;
https://www.mathworks.com/help/matlab/ref/pause.html#butxu5w-2 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)

Sign in to answer this question.