【问题标题】:Changing tick values of matlab .fig更改 matlab .fig 的刻度值
【发布时间】:2021-08-02 14:11:38
【问题描述】:

我有一个 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 秒。

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

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    如果您不想修改实际数据,那么在打开 .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
    

    【讨论】:

      【解决方案2】:

      您可以简单地在轴上查找子图并修改其 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 中使用其索引。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多