change axis range figure in matlab

To change the range of the x-axis or y-axis of a plot in MATLAB, you can use the xlim or ylim functions, respectively.

For example, if you have a line plot plot(x, y) and you want to change the x-axis range to be from 0 to 10, you can use the following command:

main.m
xlim([0, 10]);
15 chars
2 lines

Similarly, if you want to change the y-axis range to be from -5 to 5, you can use:

main.m
ylim([-5, 5]);
15 chars
2 lines

If you need to change both x-axis and y-axis range at the same time on a single plot, you can use the function axis([xmin, xmax, ymin, ymax]). For example:

main.m
axis([-5, 15, -10, 10]);
25 chars
2 lines

This command will set the x-axis range to be from -5 to 15 and y-axis range to be from -10 to 10.

related categories

gistlibby LogSnag