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:
Callback function is not executed while Matlab is busy

Subject: Callback function is not executed while Matlab is busy

From: Eric

Date: 12 Sep, 2008 07:14:03

Message: 1 of 3

Hi!

I have the problem that Matlab doesn't execute the callback-function assigned to a command button in the following situation:

I wrote an m-function which performs some longer calculation. In order that one is able to abort them, I created a small figure with an abort button. When this button is pressed a global variable is set 'true' within the callback-function. This variable is checked constantly by the calculation function which ends if 'true'.

I (normally) open the figure using the m-file created by guide from within the m-function which performs the calculation.

The problem is that the callback-function isn't executed when the calculation runs. If I force the calculation to pause using this command and if I click on the button during(!) this pause it works.

For this behaviour, it makes no difference if I open the figure by calling the m-file created by guide or by using openfig. Nor do anything change if I open the figure seperatly from the command windows, before calling the calculation function. (I tested the function on 2007b and 2008a.)

Is there any command to set up a higher priority for the callbacks? Or is there any other way to achieve the desired behaviour?

I'd be grateful for any hint.
Thanks,
Eric

Subject: Callback function is not executed while Matlab is busy

From: Titus

Date: 12 Sep, 2008 08:48:20

Message: 2 of 3


"Eric " <noemail@noemail.com> schrieb im Newsbeitrag
news:gad4rr$d9t$1@fred.mathworks.com...
> Hi!
>
> I have the problem that Matlab doesn't execute the callback-function
> assigned to a command button in the following situation:
>
> I wrote an m-function which performs some longer calculation. In order
> that one is able to abort them, I created a small figure with an abort
> button. When this button is pressed a global variable is set 'true' within
> the callback-function. This variable is checked constantly by the
> calculation function which ends if 'true'.
>
> I (normally) open the figure using the m-file created by guide from within
> the m-function which performs the calculation.
>
> The problem is that the callback-function isn't executed when the
> calculation runs. If I force the calculation to pause using this command
> and if I click on the button during(!) this pause it works.
>
> For this behaviour, it makes no difference if I open the figure by calling
> the m-file created by guide or by using openfig. Nor do anything change if
> I open the figure seperatly from the command windows, before calling the
> calculation function. (I tested the function on 2007b and 2008a.)
>
> Is there any command to set up a higher priority for the callbacks? Or is
> there any other way to achieve the desired behaviour?
>
> I'd be grateful for any hint.
> Thanks,
> Eric
>
>
>
>
>

Hi Eric,

pause is already the right thing to do. Or use drawnow(); once in a while.
Both have the effect that it allows MATLAB to process the event queue (i.e.,
your click on the button). It should(!) work also when clicking on the
button when the pause you called is not actually waiting...

Titus

Subject: Callback function is not executed while Matlab is busy

From: Eric

Date: 12 Sep, 2008 11:06:02

Message: 3 of 3

"Titus" <titus.edelhofer@mathworks.de> wrote in message <gadacl$qnj$1@fred.mathworks.com>...
>> [...]
>
> Hi Eric,
>
> pause is already the right thing to do. Or use drawnow(); once in a while.
> Both have the effect that it allows MATLAB to process the event queue (i.e.,
> your click on the button). It should(!) work also when clicking on the
> button when the pause you called is not actually waiting...
>
> Titus
>
>

Hi Titus,

thank you very much!
drawnow() works, pause(0.01) as well.
(I can't reproduce what I did wrong when I tested the function with pause on my own.)

Eric

Tags for 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