开发者

Matlab: Plot a subplot with hold on and hold off in a loop without always calling xlabel, ylabel, xlim, etc

开发者 https://www.devze.com 2023-02-20 11:41 出处:网络
Matlab question: this might be really simple but I can\'t figure it out...I\'m pretty new. I have a plot window, broken up into two subplots, lets call them A and B, which have different labels and li

Matlab question: this might be really simple but I can't figure it out...I'm pretty new. I have a plot window, broken up into two subplots, lets call them A and B, which have different labels and limits. I (hold on), make several plots to B, then I (hold off), then start iterating. In the loop, I want to update both A and B with NEW plots, but I want the axis labels, and xlim and ylim to stay the same, WITHOUT having to call xlabel, xlim, etc every iteration.

Now, (hold off) destroys a开发者_如何学运维ll axis properties. How do I save the axis properties so I don't have to keep calling xlabel, etc in the loop? I've tried newplot, setting the Nextplot property, etc to no avail. I'd like a simple solution please...not something like re-writing the plot command. Thanks!

hfig=figure();
hax = axes('Parent',hfig);
plot(hax,x,y);
hold on
plot(hax,x1,y1);
%this hold off resets the axes
hold off
while (1)
  subplot('Position',[.07 .05 .92 .44]);
  %I want to do this without having to call xlabel, ylabel, etc
  %over and over
  plot(newx, newy);
  xlabel()
  ylabel()
  hold on
  plot(newx1, newx2)
  hold off
...
end


One solution here is to initialize your plot and axes properties before your loop, then within your loop set the 'NextPlot' property of the axes to 'replacechildren' so that only the plot objects (and not the axes settings) will be changed on the next call to PLOT:

hFigure = figure();
hAxes = axes('Parent',hFigure);
plot(hAxes,x,y);
hold on;
plot(hAxes,x1,y1);
xlabel(...);  %# Set the x label
ylabel(...);  %# Set the y label
xlim([...]);  %# Set the x limits
ylim([...]);  %# Set the y limits
while (1)
  set(hAxes,'NextPlot','replacechildren');
  plot(hAxes,newx,newy);
  hold on;
  plot(hAxes,newx1,newx2);
  ...
end

This should maintain the settings for hAxes when new data is plotted in the loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消