代码之家  ›  专栏  ›  技术社区  ›  Surstroemmingpirat

Matlab:在文本框中应用科学符号

  •  2
  • Surstroemmingpirat  · 技术社区  · 7 年前

    我想在绘图中添加一个文本框,其中数字以科学记数法显示。 这是我的代码:

    fano = 74585849.3443; figure; plot(x,y) annotation('String',['fano =',num2str(fano)],'FitBoxToText','on');

    1 回复  |  直到 7 年前
        1
  •  2
  •   Alex Kraljic    7 年前

    . 下面是三个不同小数位数的示例。当用%M.Nd格式化文本时,M指定字段宽度,N表示精度(小数位数),d表示小数(有符号)。下面是三个不同的示例,小数点后2位、5位和8位。dim是一个数组,文本框的位置和大小以图形大小的归一化单位表示,格式为[x\u位置y\u位置宽度高度]。在您的情况下,宽度和高度无关紧要,因为您使用的是“FitBoxToText”属性。

    fano = 74585849.3443;
    figure;
    x = 0:0.01:10;
    y = sin(2*pi*1*x);
    plot(x,y);
    dim = [.5 .85 .0 .0];
    str = sprintf('fano = %0.2d',fano);
    annotation('textbox',dim,...
        'String',str,...
        'FitBoxToText','on',...
        'BackgroundColor','white');
    dim = [.5 .65 .0 .0];
    str = sprintf('fano = %0.5d',fano);
    annotation('textbox',dim,...
        'String',str,...
        'FitBoxToText','on',...
        'BackgroundColor','white');
    dim = [.5 .45 .0 .0];
    str = sprintf('fano = %0.8d',fano);
    annotation('textbox',dim,...
        'String',str,...
        'FitBoxToText','on',...
        'BackgroundColor','white');
    

    enter image description here