MATLAB: Does MATLAB 7.4 (R2007a) and (R2006b) freeze when I open and close an Input Dialog Box (or other graphics objects) in the program till the time the program completes

freezehanginputdlgMATLABunresponsive

When the following code is run in MATLAB 7.4 (R2007a) or MATLAB 7.3 (R2006b)
prompt = {'Enter your name:'};
dlg_title = 'Enter your name';
num_lines = 1;
def = {'No name'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
while(1)
1+1; % Dummy endless while loop
end;
an input dialog box is opened. After the input dialog box is closed, the program continues in an endless loop. During this period, MATLAB desktop stops responding after a few seconds. As a result it is not possible to access any of the MATLAB desktop windows like MATLAB Editor, MATLAB command window etc. It is also not possible to escape the program using Ctrl+C.
This behavior is not observed in MATLAB 7.2 (R2006a) and earlier versions.

Best Answer

This is a bug in MATLAB 7.4 (R2007a) and MATLAB 7.3 (R2006b) in the way MATLAB desktop graphics are refreshed during program execution.
To work around this issue, the MATLAB desktop should be refreshed using the DRAWNOW command after the input dialog box (or other graphics objects) are operated on. An example implementation is shown below:
prompt = {'Enter your name:'};
dlg_title = 'Enter your name';
num_lines = 1;
def = {'No name'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
drawnow;
while(1)
1+1;
end;