How can I make waitbar in MATLAB modal

I am working on a MATLAB GUI where I have to show a progress bar. I have two problems with the waitbar function:

  1. I want to make the progress bar modal, so that user can't do any other thing on the GUI while the progress bar is shown.

  2. There is the minimize button and the close button at the top right corner of the bar (pretty much like any other window). If you press the close button, the progress bar closes, I want this button to be hidden or disabled so that the user can't close the bar.

How can I implement these behaviours?


ANSWERS:


Example:

plot(sin(1:100))
h = waitbar(0, 'Please wait...');
set(h, 'WindowStyle','modal', 'CloseRequestFcn','');
for i=1:10
    waitbar(i/10, h);
    pause(.5)
end
delete(h)

screenshot

By setting CloseRequestFcn to empty string, clicking the close button will do nothing. You just have to wait for the loop to finish.

Note that you can still hit Ctrl+c to kill the running computation (which I think is a good thing, you don't want to annoy the user after all!)


For number 1 there you should look into threading within Matlab. You'll likely need the parallel computing toolbox to gain access to the necessary functions. You can find out more here.

As far as number 2 goes. You should be able to override the close function in the code for the GUI.

It would be something along the lines of this:

function MyWaitBar_CloseRequestFcn(hObject, eventdata, handles)

delete(hObject); % This of course deletes the object and we don't want this.  

So you would just leave the function empty. But don't forget to close it at some point!



 MORE:


 ? Get waitbar value in Matlab
 ? waitbar matlab before start a standalone script
 ? matlab progress bar not depanding on time
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar: how to add an animation?
 ? JavaFX ProgressBar problems
 ? JavaFX ProgressBar Wont Reset
 ? How can you send information to the windows task bar from java o javafx