. 下面是三个不同小数位数的示例。当用%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');