Stop the execution of a function with a push button (GUIDE)
Show older comments
Hiya!
I have a program, which analyzes a series of images extracting data from them. Now, I have been asked to make a gui in order to be more easily used. I have gotten stuck in the part where I call the program itself from the gui (which, by the moment, is a separate program (m-file)).
The calling of the program is easy, and it works. But, the proccess is long, and sometimes the user wants to stop it, in order to change configuration, for example. I can't do the cancelling part. Here is a scheme of what I've got, and what do I want
[GUIDE]
button -> Calls program.m (and it runs well)
button2 -> Stops program.m (this doesn't work) by changing the 'closing' variable to 1
[program.m]
while i< number of images if 'closing' == 1 -> exit program if not -> analyze the i image
Thank you in advance for your time and your response
Accepted Answer
More Answers (2)
Image Analyst
on 24 May 2015
I have not found a way to do it with a pushbutton. Using it to set a flag, like "finishNow", that you can check in your intensive loop, does not seem to work. The only way I can get something like that to work is to have a checkbox. So you do something like
% Clear flag and make it visible.
set(handles.chkFinishNow, 'Value', 0);
set(handles.chkFinishNow, 'Visible', 'on');
% Now the intensive loop
for k = 1 : 1000000
% Heavy duty code.
% At and of loop, see if user wants to quit
if get(handles.chkFinishNow, 'Value')
% User checked the box
break; % exit the loop
end
end
% Clear flag and make it invisible.
set(handles.chkFinishNow, 'Value', 0);
set(handles.chkFinishNow, 'Visible', 'off');
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!