How to set the axis scale in Matlab?
In Matlab, you can use the xticks and yticks functions to set the axis ticks. Here is an example of how to use them:
% 创建示例数据
x = linspace(0, 2*pi, 100);
y = sin(x);
% 绘制曲线
plot(x, y)
% 设置x轴刻度
xticks([0 pi 2*pi])
xticklabels({'0', '\pi', '2\pi'})
% 设置y轴刻度
yticks([-1 0 1])
yticklabels({'-1', '0', '1'})
In the examples above, the xticks and yticks functions are used to set the tick positions on the axes by passing a vector to specify these positions. The xticklabels and yticklabels functions are used to set the tick labels by passing a cell array to specify these labels. It should be noted that the yticks and yticklabels functions can be omitted; if the y-axis ticks are not set, Matlab will automatically set the ticks according to the data range.