Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Obviously, we don't know how "funky" your figures are, but it should be noted in such a case that the cleanest solution would be to modify the function <code>myFunkyFigure</code> such that it accepts <a href="http://www.mathworks.com/help/techdoc/ref/varargin.html" rel="nofollow noreferrer">additional optional arguments</a>, specifically the handle of an axes in which to place the plot it creates. Then you would use it like so:</p> <pre><code>hSub1 = subplot(2,1,1); %# Create a subplot myFunkyFigure(dataSet1,hSub1); %# Add a funky plot to the subplot axes hSub2 = subplot(2,1,2); %# Create a second subplot myFunkyFigure(dataSet2,hSub2); %# Add a funky plot to the second subplot axes </code></pre> <p>The default behavior of <code>myFunkyFigure</code> (i.e. no additional arguments specified) would be to create its own figure and place the plot there.</p> <p>However, to answer the question you asked, here's a way to accomplish this given that you are outputting the <em>axes handles</em> (not the <em>figure handles</em>) in the vector <code>fig</code> (<strong>note:</strong> this is basically <a href="https://stackoverflow.com/questions/4008880/producing-subplots-to-then-combine-them-into-a-figure-later-matlab/4010043#4010043">the same solution as the one given in the other question</a>, but since you mention having trouble adapting it I thought I'd reformat it to better fit your specific situation):</p> <pre><code>hFigure = figure(); %# Create a new figure hTemp = subplot(2,1,1,'Parent',hFigure); %# Create a temporary subplot newPos = get(hTemp,'Position'); %# Get its position delete(hTemp); %# Delete the subplot set(fig(1),'Parent',hFigure,'Position',newPos); %# Move axes to the new figure %# and modify its position hTemp = subplot(2,1,2,'Parent',hFigure); %# Make a new temporary subplot %# ...repeat the above for fig(2) </code></pre> <p>The above will actually <em>move</em> the axes from the old figure to the new figure. If you want the axes object to appear in <em>both</em> figures, you can instead use the function <a href="http://www.mathworks.com/help/techdoc/ref/copyobj.html" rel="nofollow noreferrer">COPYOBJ</a> like so:</p> <pre><code>hNew = copyobj(fig(1),hFigure); %# Copy fig(1) to hFigure, making a new handle set(hNew,'Position',newPos); %# Modify its position </code></pre> <p>Also note that <a href="http://www.mathworks.com/help/techdoc/ref/subplot.html" rel="nofollow noreferrer">SUBPLOT</a> is only used here to generate a position for the tiling of the axes. You could avoid the need to create and then delete subplots by specifying the positions yourself.</p>
    singulars
    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.
    3. 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