title: Close all GUI:s if main GUI is closing
body: <p>I can close my main gui with a menu or the x button</p>
  
  <pre><code>function menuProgramQuit_Callback(hObject, eventdata, handles)
  close(handles.figure1);
  </code></pre>
  
  <p>However at the same time a sub gui dialog might be open</p>
  
  <pre><code>function pushbuttonCalibrationConfigure_Callback(hObject, eventdata, handles)
  calibrationOutput = uiConfigureCalibration('uiMain', handles.figure1);
  waitfor(calibrationOutput);
  guidata(handles.output,handles);
  </code></pre>
  
  <p>If the main figure was close the sub gui is not and further it crashes when he subgui (here 
  <code>uiConfigureCalibration</code>) is closed, because the figure handle of the main gui is invalid.</p>
  
  <p>So how can I close all sub guis in matlab before I close the main gui ?</p>
  
  <p>EDIT:
  I changed the code such that the called dialog saves its handle to the handles of the main dialog</p>
  
  <pre><code>function uiConfigureCalibration_OpeningFcn(hObject, eventdata, handles, varargin)
  % Choose default command line output for uiConfigureCalibration
  handles.output = hObject;
  % Update handles structure
  guidata(hObject, handles);
  % save handle of calling gui
  mainGuiHandleIndex = find(strcmp(varargin, 'uiMain'));
  if ~isempty(mainGuiHandleIndex)
      handles.mainHandle = varargin{mainGuiHandleIndex+1};
      handlesMain = guidata(handles.mainHandle);
      handlesMain.('openfigures').('calibration') = handles.figure1;
      guidata(handles.mainHandle, handlesMain);
      guidata(handles.figure1, handles);
  end
  </code></pre>
  
  <p>In the closing function in the main gui I can no check if the figure us open and close it before the main figure is closed</p>
  
  <pre><code>if isfieldRecursive(handles, 'handles.openfigures.calibration') 
      close(handles.openfigures.calibration);
  end
  close(handles.figure1);
  </code></pre>
  
  <p>That however changes nothing. The sub-dialog figure is only closed AFTER the main dialog closes and the whole code crashes again.</p>
  
  <p>Why is the figure of the sub dialog NOT closed with the close command?</p>