title: Matlab: getting GUI handle value from a callback function when calling by another function
body: <p>I am new to GUI programming for MATLAB, so my question relates to that. </p>
  
  <p>Let's say that I create a GUI with GUIDE. In the creation function</p>
  
  <pre><code>MyGUI_OpeningFcn(hObject, eventdata, handles, varargin)
  </code></pre>
  
  <p>I call another function, </p>
  
  <pre><code>SamplingRate_Callback(handles.SamplingRate, eventdata, handles)
  </code></pre>
  
  <p>defined as</p>
  
  <pre><code>function SamplingRate_Callback(hObject, eventdata, handles)
  </code></pre>
  
  <p>SamplingRate_Callback sets a few variables, </p>
  
  <pre><code>handles.a = 1;
  handles.b = 2;
  handles.c = 3;
  </code></pre>
  
  <p>The <code>handles</code> structure updates correctly within the <code>SamplingRate_Callback</code> function. The problem I am having is that unless I change the function to </p>
  
  <pre><code>function handles = SamplingRate_Callback(hObject, eventdata, handles),
  </code></pre>
  
  <p>I cannot return the data to the calling function, <code>MyGUI_OpeningFcn</code>. I have tried using <code>guidata(gcf, handles)</code> and <code>guidata(hObject, handles)</code>, but neither works. </p>
  
  <p>Would you be able to shed some light on this problem?</p>
  
  <p>Also, I am not sure when to use <code>guidata(gcf, handles)</code> vs. <code>guidata(hObject, handles)</code>. </p>
  
  <p>Thanks for your help!</p>