Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are three ways I found to do this:</p> <p><strong>Method 1:</strong> Use <a href="http://www.mathworks.com/help/techdoc/ref/setappdata.html" rel="noreferrer"><code>setappdata</code></a> and <a href="http://www.mathworks.com/help/techdoc/ref/getappdata.html" rel="noreferrer"><code>getappdata</code></a> like so:</p> <pre><code>setappdata(0,'some_var',value) some_other_var = getappdata(0,'some_var') </code></pre> <p>You would use setappdata() in the m-file for fig1 to store whatever data you wanted to pass around, and then call getappdata() in another m-file to retrieve it. The argument <code>0</code> to the two functions specifies the MATLAB root workspace, which is accessible by your program everywhere (i.e. it is global). As such, when you close your figures that data will still be available. You may want to use <a href="http://www.mathworks.com/help/techdoc/ref/rmappdata.html" rel="noreferrer"><code>rmappdata</code></a> to remove them.</p> <p><strong>Method 2:</strong> Use <a href="http://www.mathworks.com/help/techdoc/ref/guidata.html" rel="noreferrer"><code>guidata</code></a>:</p> <p>Assuming you created your GUI with GUIDE, then you have access to a structure called <code>handles</code> which is passed around everywhere and which you can edit, and so you can do this in a GUI callback:</p> <pre><code>handles.some_var = some_value guidata(hObject,handles) </code></pre> <p>Then you can access <code>handles.some_var</code> elsewhere in some other callback (because <code>handles</code> is automatically passed into it for you) in your other m-file:</p> <pre><code>some_other_var = get(handles.some_var) </code></pre> <p><strong>Method 3:</strong> Use <a href="http://www.mathworks.com/help/toolbox/distcomp/userdata.html" rel="noreferrer"><code>UserData</code></a>:</p> <p>Store the variable you want from your first figure:</p> <pre><code>set(name_of_fig, 'UserData', some_var) </code></pre> <p>Then to get it from your other one:</p> <pre><code>some_other_var = get(name_of_fig, 'UserData') </code></pre> <hr> <p>(Disclaimer: My actual knowledge of MATLAB is not all that great, but it helps to be able to find good resources like <a href="https://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/2d0beabe03b79d71/37ed95b7e574f824?show_docid=37ed95b7e574f824&amp;hl=en&amp;pli=1" rel="noreferrer">this</a> and <a href="http://blinkdagger.com/matlab/matlab-gui-how-to-easily-share-data-between-two-separate-guis/" rel="noreferrer">this</a>, and even <a href="http://www.mathworks.com/help/techdoc/creating_guis/f5-998352.html" rel="noreferrer">this from the official docs</a>. What I've written here <em>may</em> be wrong, so you should definitely consult the docs for more help.)</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. 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.
    3. VO
      singulars
      1. This table or related slice is empty.
    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