Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Waitbar/Progress Bar with a Cancel button

55 views
Skip to first unread message

Vatsal

unread,
Nov 22, 2010, 1:07:03 PM11/22/10
to
Hello All,

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

vishnu kumar

unread,
Nov 22, 2010, 6:13:04 PM11/22/10
to
"Vatsal " <vat...@gmail.com> wrote in message <icebg7$jf9$1...@fred.mathworks.com>...


You need to use either exit or quit command to stop the execution abnormally.

Vatsal

unread,
Nov 23, 2010, 3:07:04 PM11/23/10
to
"vishnu kumar" <sasiv...@gmail.com> wrote in message <icetdv$hc$1...@fred.mathworks.com>...

> 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....

Thierry Dalon

unread,
Dec 22, 2010, 4:02:05 AM12/22/10
to
You can have a look to FEX awaitbar http://www.mathworks.com/matlabcentral/fileexchange/15231-awaitbar-alternative-to-waitbar.
how this is solved.
abort = awaitbar(i/n,h,['run :' num2str(i)]); % with update message
% if abort; return; end

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.

0 new messages