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:
Terminate/Quit Process

Subject: Terminate/Quit Process

From: Zubair Maalick

Date: 21 Apr, 2010 11:14:05

Message: 1 of 4


Hello,

I am building a GUI using guide tool. I want to develop a method (UI Button) which terminate the execution of program (which we done manually by Ctrl+C)

Example:
let say I have 2 Buttons .. "Run" and "Terminate" .. on pressing "Run" button, it starts some process ( let say for-loop) for around 30 minutes. I want to terminate the loop by "terminate" button.

Thanks.
Zubair

Subject: Terminate/Quit Process

From: Sean

Date: 21 Apr, 2010 12:36:05

Message: 2 of 4

"Zubair Maalick" <maalick@math.com> wrote in message <hqmmlt$roe$1@fred.mathworks.com>...
>
> Hello,
>
> I am building a GUI using guide tool. I want to develop a method (UI Button) which terminate the execution of program (which we done manually by Ctrl+C)
>
> Example:
> let say I have 2 Buttons .. "Run" and "Terminate" .. on pressing "Run" button, it starts some process ( let say for-loop) for around 30 minutes. I want to terminate the loop by "terminate" button.
>
> Thanks.
> Zubair

First off, you would want a while loop.

One method, though there are probably more elegant

run_button_Callback()
    tmanual = timer('TimerFcn', {@my_process});
    start(tmanual);

terminate_button_Callback
      global FLAG
      FLAG = 0;


%% --- Executes on button press in run_button
function run_button_Callback(hObject, eventdata, handles)
    tmanual = timer('TimerFcn', {@my_process});
    start(tmanual);

%% --- Executes on button press in terminate.
function terminate_Callback(hObject, eventdata, handles)
    running_timer = timerfind('tag', 'tstart');
    if(~isempty(running_timer))
          stop(running_timer);
    end

Subject: Terminate/Quit Process

From: Sean

Date: 21 Apr, 2010 12:50:20

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hqmrfl$if7$1@fred.mathworks.com>...
> "Zubair Maalick" <maalick@math.com> wrote in message <hqmmlt$roe$1@fred.mathworks.com>...
> >
> > Hello,
> >
> > I am building a GUI using guide tool. I want to develop a method (UI Button) which terminate the execution of program (which we done manually by Ctrl+C)
> >
> > Example:
> > let say I have 2 Buttons .. "Run" and "Terminate" .. on pressing "Run" button, it starts some process ( let say for-loop) for around 30 minutes. I want to terminate the loop by "terminate" button.
> >
> > Thanks.
> > Zubair
>

Sorry - ignore the top part!
You should just need this:

> %% --- Executes on button press in run_button
> function run_button_Callback(hObject, eventdata, handles)
> tmanual = timer('TimerFcn', {@my_process});
> start(tmanual);
>
> %% --- Executes on button press in terminate.
> function terminate_Callback(hObject, eventdata, handles)
> running_timer = timerfind('tag', 'tstart');
> if(~isempty(running_timer))
> stop(running_timer);
> end

Subject: Terminate/Quit Process

From: Zubair Maalick

Date: 23 Apr, 2010 07:33:05

Message: 4 of 4


Thanks alot..

Just 2 things.. (for more understanding)

1. tmanual = timer('TimerFcn', {@my_process});
In above line we also need to assign 'tag', like:
tmanual = timer('TimerFcn', {@my_process},'Tag','tstart');

2. Is it possible to use direct function instead of function handle i.e.
 tmanual = timer('TimerFcn', 'my_function()');
I tried it, it works but then terminate button doesn't respond. error lies here or it should work?

regards
Zubair

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