Give priority to gui callback over code

17 次查看(过去 30 天)
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...

采纳的回答

Titus Edelhofer
Titus Edelhofer 2017-7-25
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 个评论
Titus Edelhofer
Titus Edelhofer 2017-7-26
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 2017-7-26
编辑:Walter Roberson 2017-7-26
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by