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:
matlab gui interrupt long program execution

Subject: matlab gui interrupt long program execution

From: David Zhang

Date: 11 Jan, 2011 22:09:05

Message: 1 of 3

Dear all:

I have a program with long execution time called within a callback:

function button_1_callback
    long_exc_time_program();
end

Within long_exc_time_program, I have a global variable, stop, so that:

function long_exc_time_program()
   global stop
   if(stop == true)
      return;
   end
end

I have another callback that set the value of stop:

function button_2_callback
   global stop
   stop = true;
end

As you can see, I want to prematurely and gracefully exit long_exc_time_program.

When I tried the above method, call button_2_callback was call AFTER long_exc_time_program is completed. My guess the the button 2 callback is in the event queue right behind long_exc_time_program, and thus need it to complete before button 2 callback is processed. Is there a way to get around this?

Subject: matlab gui interrupt long program execution

From: David Zhang

Date: 11 Jan, 2011 23:54:04

Message: 2 of 3

Update:

I found a (not very pretty, but effective work around). All I need is to add a pause(0.01) in the long_exc_time_program every so often to allow matlab to flush the event queue. Since I expect my GUI wouldn't be used much during long_exc_time_program is running, 0.01 second pause should be sufficient.

I welcome any other clean solution.

Subject: matlab gui interrupt long program execution

From: I am too much me

Date: 12 Jan, 2011 00:12:36

Message: 3 of 3

On 11-01-11 05:54 PM, David Zhang wrote:
> Update:
>
> I found a (not very pretty, but effective work around). All I need is to add a
> pause(0.01) in the long_exc_time_program every so often to allow matlab to
> flush the event queue. Since I expect my GUI wouldn't be used much during
> long_exc_time_program is running, 0.01 second pause should be sufficient.
>
> I welcome any other clean solution.

You can use drawnow() or pause(0)

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