简体   繁体   English

如何在Matlab中调整y轴绘图范围?

[英]How to Adjust y axis plot range in Matlab?

I need to plot the following functions in matlab 我需要在matlab中绘制以下函数

y1=sign(x)
y2=tanh(x)
y3=(x)/(x+1)

The x-range is -5,5 with 0.1 spacing The y-plot range should be between -1.5 to 1.5. x范围为-5,5,间距为0.1,y值范围应介于-1.5到1.5之间。

Each plot should have a labeled x and y axis and a legend in the lower right corner. 每个图应该有一个标记的x和y轴以及右下角的图例。

The only things I cant figure out is how to adjust the y plot range. 我唯一想知道的是如何调整y绘图范围。 Ive tried editing the actual figure but all that seems to do is distort the graph. 我曾尝试编辑实际的数字,但似乎所做的只是扭曲图形。 Is there a command within matlab that will let me adjust the y axis plot range? 在matlab中是否有一个命令可以让我调整y轴绘图范围?

The other thing I havent figured out yet is adding a legend, I can do it after the figure is created but I guess it needs to be done by matlab command. 我还没想到的另一件事是添加一个图例,我可以在创建图形后执行此操作,但我想它需要通过matlab命令完成。

是的,在plot命令后使用axis

axis([-5 5 -1.5 1.5])

If you only want to set the y-range without setting the x-range you can use 如果您只想设置y范围而不设置x范围,则可以使用

ylim([-1.5 1.5])

or alternatively axis([-inf inf -1.5 1.5]) . 或者axis([-inf inf -1.5 1.5]) I found this from the original MATLAB-source: https://de.mathworks.com/help/matlab/ref/ylim.html 我从最初的MATLAB源代码中找到了这个: https//de.mathworks.com/help/matlab/ref/ylim.html

PS: For trigonometric functions I would recommend to use axis equal to have equally spaced x and y-axis (see MATLAB ) PS:对于三角函数,我建议使用axis equal x和y轴等间距的轴(参见MATLAB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM