Matlab:在文本框中应用科学计数法

标签 matlab textbox scientific-notation

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

法诺 = 74585849.3443; 数字; 绘图(x,y) 注释('String',['fano =',num2str(fano)],'FitBoxToText','on'); 这里 fano 显示为十进制数。如何将格式更改为科学记数法?

最佳答案

您可以使用函数sprintf创建所需的字符串。以下是打印不同小数位数的三个示例。使用 %M.Nd 设置文本格式时,M 指定字段宽度,N 表示精度(小数位数),d 表示小数(有符号)。下面是三个不同的示例,分别具有 2 位、5 位和 8 位小数。 dim 是一个数组,其中包含文本框的位置和大小(以相对于图形大小的标准化单位表示),格式为 [x_location y_location width height]。在您的情况下,宽度和高度并不重要,因为您使用的是“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

关于Matlab:在文本框中应用科学计数法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46462611/

相关文章:

matlab - 如何确定Matlab中子图的尺寸?

javascript - 文本框 -> 立即开始输入而不是单击文本框

python - 用科学记数法Python优雅地打印

android - 在 Android Studio 中调试时如何禁用科学记数法?

matlab - 如何使用多个定界符进行文本扫描

image - 如何将组合图像嵌入在一起

r - R 中的 3d 图 - 补丁

python - 仅当在文本框中时,如何将 Enterkey <Return> 绑定(bind)到按钮?

c# - 获得焦点并选择文本时文本左对齐

python - 是否有一个 python 模块可以将值和错误转换为科学记数法?