This example shows how to change the axis limits of a graph. By default, MATLAB® chooses axis limits to encompass the data plotted.
x as 200 linearly spaced values between -10 and 10. Define
y as the sine of
x with an exponentially decreasing amplitude. Create a line plot of the data.
x = linspace(-10,10,200); y = sin(4*x)./exp(x); figure plot(x,y)
Change the axis limits by passing to the
axis function a four-element vector of the form
xmax set the scaling for the x-axis, and
ymax set the scaling for the y-axis.
You also can change the axis limits using the
zlim functions. The commands
ylim([ymin,ymax]) produce the same result as
Change the x-axis scaling to range from 0 to 10. Change the y-axis scaling to range from -1 to 1.
Use an automatically calculated minimum x-axis limit by setting its value to
-inf. MATLAB® calculates the limit based on the data. Set the maximum x-axis limit to 10, the minimum y-axis limit to -1, and the maximum y-axis limit to 1.
MATLAB calculates the minimum limit for the x-axis based on the data. To use an automatically calculated maximum limit, set the value to