title: Plotting a subplot within another subplot in MATLAB
body: <p>I am attempting to plot a subplot within another subplot in MATLAB. The problem is that the final subplot shows only portions of the smaller subplot. After some searching on the web, it seems one option here is to save the subplot into a temporary figure and add it to the final subplot after. Another way is to manually specify positions of the plots inside the final figure i.e. rolling your own subplot. I was wondering if there were a more elegant approach. Apologies in advance if this isn't possible/desirable behavior. My idea of how the code would run is:</p>
  
  <pre><code>someData = linspace(0,10);
  subplot(2,2,1);
  plotThing(someData);
  subplot(2,2,2);
  plot(cos(someData));
  
  function [ out ] = plotThing( someData )
     y1 = sin(someData);
     y2 = sin(2*someData);
     y3 = sin(4*someData);
     y4 = sin(8*someData);
     f = figure(4);
  
     subplot(2,2,1)
     plot(someData,y1)
     subplot(2,2,2)
     plot(someData,y2)
     subplot(2,2,3)
     plot(someData,y3)
     subplot(2,2,4)
     plot(someData,y4)
  
     out = f;
  end
  </code></pre>
  
  <p>My desired behavior would be to have two things in the final figure, the subplot of four items on top, and the single plot underneath. Any advice would be great.</p>
  
  <p>EDIT - The issue with the accepted answer is that it would require a significant number of subplots (12x12 in my situation). After some thought and work, I discovered that it is possible to encapsulate the contents of a subplot into a uipanel. This gives the desired behavior of a subplot being able to be treated as a unit in a larger scale figure. The code to accomplish this looks something like:</p>
  
  <pre><code>plotThing(someData, [0, 0.5, 1, 0.5]);
  panel2 = uipanel('Position', [0, 0, 1, 0.5]);
  subplot(1,1,1,'Parent', panel2); %Strange but necessary as one cannot set the parent of a plot directly
  plot(cos(someData));
  
  function [ out ] = plotThing( someData, position )
      panel = uipanel('Position', position); 
  
      y1 = sin(someData);
      y2 = sin(2*someData);
      y3 = sin(4*someData);
      y4 = sin(8*someData);
  
      subplot(2,2,1, 'Parent', panel)
      plot(someData,y1)
      subplot(2,2,2, 'Parent', panel)
      plot(someData,y2)
      subplot(2,2,3, 'Parent', panel)
      plot(someData,y3)
      subplot(2,2,4, 'Parent', panel)
      plot(someData,y4)
  end
  </code></pre>
  
  <p>The result of this generalized solution look like:
  <a href="http://i.stack.imgur.com/rlWM1.png" rel="nofollow">results</a></p>