一、方法
x = linspace(0,pi);
y1 = cos(x);
yyaxis left; % 激活左边的轴
plot(x,y1)
xlabel('X-axis');
ylabel('left Y-axis'); % 给左y轴添加轴标签
hold on
yyaxis right; % 激活右边的轴
y2 = cos(2*x);
plot(x,y2)
ylim([-1,1]); % 设置右y轴的界限
ylabel('right Y-axis'); % 给右y轴添加轴标签
二、更改坐标轴颜色
x = linspace(0,pi);
y1 = cos(x);
yyaxis left; % 激活左边的轴
plot(x,y1,'r')
xlabel('X-axis');
ylabel('left Y-axis'); % 给左y轴添加轴标签
ax = gca;
ax.YColor = 'r';
hold on
yyaxis right; % 激活右边的轴
y2 = cos(2*x);
plot(x,y2,'b')
ylim([-1,1]); % 设置右y轴的界限
ylabel('right Y-axis'); % 给右y轴添加轴标签
ax = gca;
ax.YColor = 'b';