Exit in matlab blocked by questdlg in finish.m

Alec Jacobson

July 31, 2013

weblog/

I was using matlab with the -nodesktop option from the command line. I tried to exit but I was blocked by the following error message:
Error using figure
This functionality is no longer supported under the options used to start this instance of MATLAB. For more
information, see "Startup Option Changes on Mac" in the MATLAB Release Notes. To view the release note in your
system browser, run  web('http://www.mathworks.com/help/matlab/release-notes.html#startup_options_changes',
'-browser')

Error in getnicedialoglocation (line 19)
    convertData.hFig = figure('visible','off');

Error in questdlg (line 140)
FigPos    = getnicedialoglocation(FigPos, get(0,'DefaultFigureUnits'));

Error in finish (line 1)
button = questdlg('Are you sure you want to quit?', 'Exit Dialog','Cancel','Quit','Cancel');
The problem was that I have placed a safety prompt in my finish.m script that double checks whether I want to quit. But with the nodesktop option I get an error trying to create the prompt and then the quit is aborted. I temporarily got around this by redefining questdlg:
questdlg = @(varargin) 2;
Then I could exit. Note: I also have something in my finish.m that saves the state of the last session. So to get my prompt to come back I had to remove/delete this redefinition of questdlg that was saved in that state. Update: The real solution is to enclose my prompt in finish.m inside an:
if usejava('desktop')
...
end