. Advertisement .
..3..
. Advertisement .
..4..
MATLAB is a worldwide language, but not anyone can grasp how to handle it right. Axis limit MATLAB functions, specifically, are indeed what may cause you severe headaches.
Jump right in for further helpful details regarding ways to access them adequately!
How To Establish an Axis Limit MATLAB?
There are 5 approaches in total to set axis limits in MATLAB. Scroll down to grasp more what they are!
Utilize The Xlim() Function
The x-axis limits for the current axes or chart are specified using xlim(limits). As such, limits should be specified as a two-element vector of the form [xmin xmax], with xmax bigger than xmin.
Running the code:
x = linspace(0,10);
y = sin(x);
plot(x,y)
xlim([0 5])
Output:
......... ADVERTISEMENT .........
..8..
Utilize The Ylim() Function
Similar to the xlim() one way or another, the y-axis limits for the current axes or chart are specified using ylim(limits). Limits are specified as a two-element vector [ymin ymax], where ymax is bigger than ymin.
Running the code:
x = linspace(0,10);
y = sin(x);
plot(x,y)
ylim([-2 2])
Output:
......... ADVERTISEMENT .........
..8..
Utilize The Zlim() Function
We can also adopt the zlim() feature to establish the axis limit. That way, limits are specified as a two-element vector [zmin zmax], where zmax is bigger than zmin.
Running the code:
[X,Y,Z] = peaks;
surf(X,Y,Z);
zlim([-5 5])
Output:
......... ADVERTISEMENT .........
..8..
Utilize The Axis() Function
Another method to mention when it comes to lay down the axis limit is making use of the axis() feature. This function defines the limits for the current axes just as the approaches above. The difference is that it creates a vector with four, six, or eight elements to represent the limits.
Running the code:
x = linspace(0,2*pi);
y = sin(x);
plot(x,y,'-o')
Output:
......... ADVERTISEMENT .........
..8..
Utilize The Set() Function
After charting the variables, you may use the set() method to specify simply the y-axis, x-axis, or z-axis limit. To do so, you must supply the name of the axis and its limit to this function to set the limit of that axis.
Take a look at the code below.
set(gca,'axisName',[Min Max])
The name of the axis is axisName, the highest value of the specified axis is Max and the lowest value of the defined axis is Min in the above code. After that, all you have to do is to employ the function listed as follows to set the x-axis boundaries.
Running the code:
set(gca,'XLim',[-1.5 1.5])
And that’s how we gain the x-axis’ limit from -1.5 to 1.5.
The Bottom Line
This tutorial is aimed to bring forth some great methods on how to build axis limit MATLAB. Hopefully, you have racked up useful insight regarding such a field somehow. Also, don’t hesitate to leave a comment if you have any further questions regarding MATLAB language. Good luck with your coding then!
Leave a comment