Format Number (exponential notation)
显示 更早的评论
I have a code and a result is the variabile: T= 5.6789e-05
I want use a function for change the exponential notation from e-05 to e-6 and print the value in a graph.
Correct value T= 56.789e-06
Help me
sprintf('time T= %3.3e\n',T)
回答(1 个)
Walter Roberson
2020-3-23
1 个投票
You will not be able to do this directly. sprintf and related do not offer any control over where the decimal is put.
You can use log10 to probe the power of 10 for the value, such as -5. Divide by that power minus 1 to get a value with two leading decimals. Format that. Add on sprintf('e%d') the power minus 1
5 个评论
Matteo Peruzzi
2020-3-23
Walter Roberson
2020-3-23
X=5.6789e-05; D=floor(log10(5.6789e-05))-1; X/10^D
gives 56.789.
Matteo Peruzzi
2020-3-23
Walter Roberson
2020-3-23
X=5.6789e-05;
D=floor(log10(5.6789e-05))-1;
t2S = sprintf('time to half time t2=%.4fe%d', X/10^D, D) ;
and use the variable in constructing the legend.
Matteo Peruzzi
2020-3-23
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!