改变 matlab .fig 的刻度值

Changing tick values of matlab .fig

我有一个给我的 matlab 图,其中 x 轴值的范围从 0 到 4500 个时间步长。每个时间步对应 1.8e-8 秒。我想将刻度转换为秒,所以我有 0,0.0900,0.1800,0.2700,0.3600,0.4500,0.5400,0.6300,0.7200,0.8100 秒。

有没有办法在绘图仪中做到这一点?

如果您不想修改实际数据,那么一旦您打开 .fig 文件,您可以通过以下操作简单地更改标签

set(gca, 'XTickLabel' , {'0' '0.09' '0.18' '0.27' '0.36' '0.45' '0.54' '0.63' '0.72' '0.81'})

如果您想修改数据,那么在打开图形文件后,您可以先使用 gca 获取轴的句柄,然后获取图的句柄,最后获取底层数据并修改:

ax1 = gca;                          % get the handle to the axis
plt1 = get(ax1,'Children');         % get the handle to the plot
xdata = get(plt1,'XData');          % retrieve x data from the plot
xdata_seconds = xdata * 1.8e-4;     % convert x data to desired units
set(plt1, 'XData', xdata_seconds)   % put the new data into the plot

您可以简单地在轴中查找子图并修改其 XData:

x = 1:4500;
y = rand(size(x));
ax = axes;
plot(ax, x, y, '-r');

绘图现在的刻度从 1 到 4500。

ax.Children.XData = ax.Children.XData.*1.8e-8;

现在转换为秒级。

如果坐标轴包含多个子坐标轴,您可能希望找到正确的坐标轴并在调用 ax.Children(idx).XData.

中使用其索引