title: Matlab draw 'subaxis' based subplots on specified 'axes'
body: <p>I am coding some GUI staff using Matlab. And I want to plot a figure with subfigures in one specified 'axes' using 'subaxis' method (which can be download on Matlab FX <a href="http://www.mathworks.co.uk/matlabcentral/fileexchange/3696-subaxis-subplot" rel="nofollow">subaxis.m</a>).</p>
  
  <p>The program behaves quite right at first. As the subfigures are updating by one click button. Then the error pops-up. I simplify the problem and write some testing codes as following:</p>
  
  <pre><code>% Specify an 'axes' in my GUI (here is an example of axes handle called 'ax')
  ax = axes;
  axes(ax); 
  cla(ax, 'reset');
  
  % Plot something using 'subaxis' with multiple subfigures 
  x = 0:0.1:10;
  spacing = 0.0;
  subaxis(3,1,1,'Spacing',spacing);
  plot(x,rand(size(x)),'k')
  legend('D','Location','NorthWest')
  ylim([-0.2 1])
  set(gca, 'box','off')
  set(gca,'XAxisLocation','top')
  
  subaxis(2,'Spacing',spacing);
  plot(x,rand(size(x)),'r')
  legend('C','Location','NorthWest')
  ylim([-0.2 1])
  set(gca,'xtick',[],'box','off','xcolor','w')
  
  subaxis(3,'Spacing',spacing);
  plot(x,rand(size(x)),'b')
  legend('B','Location','NorthWest')
  set(gca, 'box','off')
  </code></pre>
  
  <p>The program is fine at this point and did what I expected. Now I press a button to update these subfigures, but still want to plot the subfigures in the specified axes called 'ax':</p>
  
  <pre><code>axes(ax); 
  cla(ax, 'reset');
  
  x = 0:0.1:10;
  spacing = 0.0;
  subaxis(3,1,1,'Spacing',spacing);
  plot(x,rand(size(x)),'k')
  legend('D','Location','NorthWest')
  ylim([-0.2 1])
  set(gca, 'box','off')
  set(gca,'XAxisLocation','top')
  
  subaxis(2,'Spacing',spacing);
  plot(x,rand(size(x)),'r')
  legend('C','Location','NorthWest')
  ylim([-0.2 1])
  set(gca,'xtick',[],'box','off','xcolor','w')
  
  subaxis(3,'Spacing',spacing);
  plot(x,rand(size(x)),'b')
  legend('B','Location','NorthWest')
  set(gca, 'box','off')
  </code></pre>
  
  <p>Error shows up!!!</p>
  
  <pre><code>Error using axes
  Invalid object handle
  </code></pre>
  
  <p>Not sure what to do as the error info is so brief. It seems the subaxis can only be plot to a specific 'axes' once.</p>
  
  <p>Any help would be appreciated. Thanks very much. A.</p>