title: clear workspace of GUI matlab
body: <p>I have a <strong>new</strong> button in my GUI here is its callback:  </p>
  
  <pre><code>function ptlNew_ClickedCallback(hObject, eventdata, handles)  
  % hObject    handle to ptlNew (see GCBO)  
  % eventdata  reserved - to be defined in a future version of MATLAB  
  % handles    structure with handles and user data (see GUIDATA)  
  cla(handles.axes1,'reset');  
  clear variables  
  </code></pre>
  
  <p>but the last line doesn't work<br>
  what can I do to clear workspace of my GUI without closing it to feed up memory?<br>
  my variables are in handles structure<br>
  for example if I have variable X, I should access it in form handles.X<br>
  I made my variables properties of handle because I wanted to access them in more than one callback function and I didn't want to make them Global  </p>
  
  <p>Also I tried to clear a specific variable. so instead of <strong>clear variables</strong> I used this line of code<br>
      clear handles.FiducialPixels<br>
  But it doesn,t work too and when I try to access it in the next line by code:<br>
      handles.FiducialPixels<br>
  it is printed on the Command Window quitely as it was before<br>
  I'm really confused what can I do?
  The interesting issue is that line <strong>clear variables</strong> or <strong>clear  handles.FiducialPixels</strong> don't make any error or warning but they do their task!  </p>
  
  <p>As Li-aung Yip answered I changed the call back to this form:</p>
  
  <pre><code>function ptlNew_ClickedCallback(hObject, eventdata, handles)
  names = fieldnames(handles);
  rmfield(handles,'FiducialPixels');
  names = fieldnames(handles)
  handles.FiducialPixels  
  </code></pre>
  
  <p>but this is what appeares on the command line running lines 4 and 5:  </p>
  
  <p>names = </p>
  
  <pre><code>'figure1'
  'pnlControlPointsImageCoordinates'
  'uitoolbar1'
  'pnlCalculateParameters'
  'mnuInteriorOrientation'
  'btnLoad2'
  'edtImageFile'
  'text17'
  'edtInteriorOrientation'
  'edtF'
  'text16'
  'edtYPPA'
  'text15'
  'edtXPPA'
  'text14'
  'text13'
  'btnBrowseLensDistortion'
  'edtLensDistortion'
  'text12'
  'btnBrowseInteriorFile'
  'text11'
  'axes2'
  'uitoggletool3'
  'uitoggletool2'
  'uitoggletool1'
  'ptlNew'
  'txtCalculation'
  'btnJumpTo'
  'btnLoad'
  'edtImagePath'
  'text9'
  'btnSaveParameters'
  'btnCalculate'
  'edtNumber'
  'text8'
  'uitable1'
  'btnGinput'
  'btnBrowse'
  'edtFilePath'
  'text1'
  'btngrpTypeOfOrientation'
  'axes1'
  'mnuItemControlPointsImageCoordinates'
  'mnuItemCalculateParameters'
  'rdbtnProjective'
  'rdbtnAffine'
  'rdbtnConformal'
  'output'
  'TableData'
  'TableDataEmpty'
  'Matrix'
  'FiducialImageCoordinates'
  'dataH'
  'FiducialPixels'
  'flag'
  'X'
  </code></pre>
  
  <p>592 handles.FiducialPixels</p>
  
  <p>ans =</p>
  
  <p>1.0e+003 *</p>
  
  <pre><code>7.5294    3.8246
  0.1357    3.8723
  3.9200    0.2311
  3.8882    7.4499
  7.4817    0.2311
  0.2152    7.5294
  0.2311    0.2311
  7.4658    7.4817
  </code></pre>
  
  <p>You see handles.FiducialPixels still exists<br>
  Even if you use <strong>guidata(hObject,handles)</strong> after the third line, the result will be the same</p>