I am sure most of you have seen a similar question several times. I did try looking for an answer to my question but could not find anything useful.
I am in the process of creating a GUI for scripts that use several other functions to generate the output and this entire process takes several hundred seconds to finish... Now to keep the user informed about the progress, I am trying to include the wait/progress bar with a cancel button and also have the waitbar update automatically.
All the examples that I have found here, they all use the waitbar in the loop, but in my case, I cannot use a loop. This is how my code looks in the GUI:
function Run_Model_Callback(hObject, eventdata, handles)
% hObject handle to Run_Model (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic
msgbox(pwd);
h = waitbar(0,'Please Wait...Running','CreateCancelBtn','cancelButton = 1;closereq;');
do all the steps and generate output
delete(h)
In this, when I click on the cancel button, it does close the waitbar but the function is still running. How can I stop the functions from running once I click on the cancel button? If someone has any suggestion, I would also like to add a message box that would ask the user to confirm if he/she wants to actually stop the execution.
Also, since I am not using the waitbar in any loop, my status bar does not get updated. Any idea about this?
Thank you for you help.
Regards,
VS
You need to use either exit or quit command to stop the execution abnormally.
Hello Vishnu,
Thanks for your response.
I did try to implement a quit command, but it just closes the progress bar, the function still keeps running....
Return will exit the function.
The problem of your solution ('CreateCancelBtn','cancelButton = 1;closereq;') is that the cancelButton=1 is not evaluated / returned / accessible in your function workspace.