MATLAB: How to get UIWAIT to work with a question dialog box in MATLAB

MATLABmsgboxquestdlguiwait

I am trying to open a dialog box, stop the program it is called from, then after a certain time, close the dialog box and return to the program.
The function UIWAIT works properly for the MSGBOX function:
uiwait(msgbox('Welcome to the Advection Program','Hello'),.2);
However, when I try to use it for the QUESTDLG function it does not work.
I am executing the following code:
uiwait(questdlg('Are you sure, you want to stop Realtime?','CloseRequestFunction','Yes','No','Yes'),.2);
After this, I close the dialog box. However, the following error is returned:
??? Error using ==> uiwait
Input argument must be of type figure

Best Answer

You receive this error message using QUESTDLG because UIWAIT expects its first input argument to be a function handle (which is the case for MSGBOX, but not for QUESTDLG).
The attached file, 'My_questdlg.m' closely reproduces the operation of the question dialog box, and can be made to work with UIWAIT. You would have to modify it slightly to have it return an output string, if this is what you want.
In order to run this program, download the attached files into your working directory. Then run the following command at the MATLAB command prompt:
My_questdlg('Are you sure you want to stop Realtime?','Close Request Function','Yes','No')
This will open up a GUI similar to your question dialog box. If there is no user input, the figure is deleted and control is returned to the main program after an interval of 5 seconds.