Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you are designing your GUI using GUIDE, any <code>uicontrol</code> object you put on the the current figure (e.g. <code>GUI.fig</code>) will have its handle added automatically to the <code>handles</code> structure, the variable that will be passed around between callbacks. <code>handles</code> is also traditionally used to pass any other program variables between callbacks by adding those variables to the <code>handles</code> structure and saving <code>handles</code> using <code>guidata()</code> function.</p> <p>The easiest and fastest way to pass <code>handles</code> to external functions is to send it as an input parameter to those functions. For example, if your other external file is called <code>auxiliary.m</code> and contains a function called <code>auxiliary(...)</code>, just design <code>auxiliary(...)</code> to accept one extra parameter called <code>handles</code> to receive all figure handles -- plus any other manually added variables. This is exactly the way your <code>GUI.m</code> works right now. Note that <code>GUI.m</code> looks like a single file but it's really a container for a lot of callback functions, where each one of them could be a separate <code>.m</code> file containing a single function of the same name. For example, if you were to cut <code>pushbutton1_Callback(hObject, eventdata, handles)</code> out of <code>GUI.m</code> and paste it in a separate <code>pushbutton1_Callback.m</code> file, your program works the exact same way as long as there is no duplicate files of the same name.</p> <p>If you still insist on not passing the handles directly to the external function, just save the <code>handles</code> structure and load it in the second <code>.m</code> file:</p> <pre><code>% inside GUI.m save('handles.mat', 'handles'); %inside auxiliary.m load('handles.mat', 'handles'); </code></pre> <p>I recommend the first method since there is no IO overhead and you don't need data persistence.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload