How to display text in a plot as scientific number

26 ビュー (過去 30 日間)
Ziv Kassner
Ziv Kassner 2020 年 8 月 30 日
コメント済み: Ziv Kassner 2020 年 8 月 30 日
How do I display a very small/large number in text command as a number with 2 digits after the decimel point?
e.g. 5.42e-6 rather than 0.00000542 or 5.4200e-06
thanks,
Ziv

採用された回答

dpb
dpb 2020 年 8 月 30 日
Use a format string to create specific format desired...
>> sprintf('%.2e',pi*1E6)
ans =
'3.14e+06'
ergo, use
text(x,y,sprintf('%.2e',valueToPrint))
There's also num2str, compose that have some additional flexibility for specific uses...

その他の回答 (1 件)

Adam Danz
Adam Danz 2020 年 8 月 30 日
編集済み: Adam Danz 2020 年 8 月 30 日
n = 0.00000542;
nStr = num2str(n, '%.2e');
cla()
text(.1, .1, nStr)
% alternatively,
text(.5, .1, sprintf('%.2e', n))

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by