【发布时间】:2016-02-10 10:25:20
【问题描述】:
我喜欢在交互式命令行窗口中使用 MATLAB 的 shortEng 表示法:
>> a = 123e-12;
>> disp(a);
1.2300e-10 % Scientific notation. Urgh!
>> format shortEng;
>> disp(a);
123.0000e-012 % Engineering notation! :-D
但我想使用 fprintf:
>> format shortEng;
>> fprintf('%0.3e', a);
1.2300e-10 % Scientific. Urgh!
如何使用 MATLAB Format Operators 以工程格式使用 fprintf 或 sprintf 打印值?
我知道我可以编写自己的函数来将值格式化为字符串,但我正在寻找 MATLAB 中已经内置的东西。
注意:“工程”符号与“科学”符号的不同之处在于指数始终是 3 的倍数。
>> fprintf('%0.3e', a); % This is Scientific notation.
1.230000e-10
【问题讨论】:
-
好像没有内置函数来指定
fprintf输出到“工程”模式...你必须使用自己的函数