From: Zubair Maalick on

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
From: Sean on
"Zubair Maalick" <maalick(a)math.com> wrote in message <hqmmlt$roe$1(a)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
From: Sean on
"Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <hqmrfl$if7$1(a)fred.mathworks.com>...
> "Zubair Maalick" <maalick(a)math.com> wrote in message <hqmmlt$roe$1(a)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
 | 
Pages: 1
Prev: LVQ
Next: add binary constraints to portopt