Friday, April 15, 2011

How do I combine setting axes limits and zooming in a MATLAB plot?

Here is the basic situation in a MATLAB session

>> figure
>> h=axes;
>> y=sin(0:2*pi/100:pi);
>> plot(y);
>> set(h,'xlim',[20 80]);

Now I want to be able to use the figure toolbar's Zoom In/Out buttons to reset the view so that the x-axes limits are the default, (ie [0 100]). However, they only allow one to zoom in and out of the current view. There must be an easy way to set the plot view in code that allows the user to zoom out again with Figure Toolber's zoom out button. Any ideas or suggestions?

Thanks

From stackoverflow
  • Simple answer: call zoom reset before setting the axis limits. As in

    >>plot(y)
    >>zoom(gcf,'reset') % reset the zoom out point to current view
    >>set(h,'xlim',[20 60]);
    

0 comments:

Post a Comment