![如何强制 matlab 在图 X 和 Y 上显示足够的数字?](https://linux22.com/image/1322840/%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6%20matlab%20%E5%9C%A8%E5%9B%BE%20X%20%E5%92%8C%20Y%20%E4%B8%8A%E6%98%BE%E7%A4%BA%E8%B6%B3%E5%A4%9F%E7%9A%84%E6%95%B0%E5%AD%97%EF%BC%9F.png)
问题是 matlab “截断”了一些数字,我无法识别实际值。看截图,在 Y 上有很多“0.0156”,而我期望的是“0.01562”、“0.01564”、“0.01566”等。
如何使用 matlab 显示足够多的数字以便我能识别实际值?
答案1
MATLAB 7.3 (R2006b) 中不提供指定轴上刻度标签精度的功能。
要解决此问题,您可以检索刻度,将其转换为具有指定精度的字符串,并将标签设置为新的刻度标签。可以在 MATLAB 命令提示符下执行以下示例代码,以说明此解决方法:
% Create an example plot.
plot(1:10);
% Query xTick numerical values.
xTick = get(gca,'xTick');
% Create strings out of xTick numerical values with a prescribed precision.
% The format string '%a.bf' means to present the values within a field that
% is wide enough to fit 'a' digits with 'b' digits after the decimal point
% in the format of a 'f'loating point number.
xTickLabel = arrayfun( @(x) sprintf('%3.2f',x), xTick, 'uniformoutput', false);
% Use xTickLabel on the plot.
set(gca, 'xTickLabel', xTickLabel);
注意,一旦设置了刻度标签,它们就处于手动模式。刻度标签不会随着图形窗口的大小调整或窗口的放大和缩小而自动更新。
参考:https://www.mathworks.com/support/solutions/en/data/1-3P8CU0/index.html
答案2
这可能不是最好的解决方案,但它应该允许您区分值:
将所有值乘以 1000,然后添加标签或标题,清楚地表明这些值已乘以 1000。