在我的图表中添加第二个 x 轴,我可以自己缩放

Adding a second x-axis to my graph, which I can scale myself

我目前在使用 Matlab 时遇到问题,希望您能帮助我。我在下面编写了这段代码来显示图形,但现在我想在图像上方添加另一个 x 轴,我可以自己缩放它。是否有可能添加另一行:set(gca, 'XTick2', [bla:bla:bla]); and another label

编辑:我已经解决了部分问题,希望你也能帮我解决剩下的问题……我现在有 2 个轴,但还有一些问题。
标签位置错误,y 标签在刻度内,我想要两个不同的标签用于两个 x 轴。
另外我想从上面的x轴上删除下面的x轴的比例。
代码也是新的:

x1 = [0, 421.441, 842.882, 1264.323, 1685.764, 2107.205, 2528.646, 2950.087, 3371.528, 3792.969, 4214.41, 4635.851, 5057.29];
y1 = [55.659, 55.856, 56.081, 56.279, 56.312, 56.169, 56.038, 55.903, 55.75, 55.604, 55.512, 55.534, 55.661];
y2 = [51.231, 51.735, 52.063, 52.152, 51.632, 51.16, 51.014, 50.911, 50.721, 50.596, 50.597, 50.858, 51.242];
y3 = [50.939, 51.381, 51.644, 51.687, 51.353, 50.944, 50.829, 50.706, 50.538, 50.43, 50.412, 50.614, 50.948];
y4 = [50.023, 50.328, 50.506, 50.535, 50.352, 50.113, 50.032, 49.938, 49.801, 49.705, 49.672, 49.801, 50.03];
plot(x1,y1, 'ks-',x1,y2, 'bx--',x1,y3, 'gd-.',x1,y4, 'c.-'),
ax1 = gca;
ax1.XLim = [0, 5075];
ax1.XTick = 0:1000:5075;
ay1 = gca;
ay1.YLim = [49.5, 56.5];
ay1.YTick = 49.5:0.5:56.5;
ax2 = axes('Position',ax1.Position,'Color','none');
ax2.XLim = [0, 360];
ax2.XTick = 0:30:360;
ax2.XAxisLocation = 'top';
ax2.YTick = [];
grid off
xlabel('Time [s]')
ylabel('Temperature [°C]')
legend('A','B','C','D')

只需使用函数text,

text(x,y,'string') 

其中 xy 是您新 x-axis 和 string 您的 blabla.

的坐标

更新:使用此示例代码并根据您的需要进行调整

x1 = 0:0.1:40;
y1 = 4.*cos(x1)./(x1+2);
x2 = 1:0.2:20;
y2 = x2.^2./x2.^3;

figure
line(x1,y1,'Color','r')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
    'XAxisLocation','top',...
    'YAxisLocation','right',...
    'Color','none');

给出情节,