use sprintf while selecting exponential power

7 ビュー (過去 30 日間)
Walter Williams
Walter Williams 2020 年 9 月 13 日
コメント済み: Star Strider 2020 年 9 月 13 日
Hi, I am using sprintf to grab a vallue and print in a legend. They all vary with power, but i want them on the same scale. IE:
legend({sprintf('Sample A %.3E',P1),sprintf('Sample B %0.3E',P2})
Where P1 is 2.331E6 and P2 is 3.215E5, resulting in
Sample A 2.331E6 and Sample b 3.215E5
I would like them to (note exponent)
Sample A 2.331E6 and Sample b 0.321E6

採用された回答

Star Strider
Star Strider 2020 年 9 月 13 日
I wrote a utility function a while back to do just that:
rfx = @(x,xpnt) [sign(x).*10.^(log10(abs(x))-xpnt), xpnt]; % Anonymous Function Creating Reformatted Number
P1 = 2.331E6;
P2 = 3.215E5;
xpnt = +6;
Out1 = sprintf('Sample A %.7fE%+d', rfx(P1,xpnt))
Out2 = sprintf('Sample A %.7fE%+d', rfx(P2,xpnt))
producing:
Out1 =
'Sample A 2.3310000E+6'
Out2 =
'Sample A 0.3215000E+6'
.
  2 件のコメント
Walter Williams
Walter Williams 2020 年 9 月 13 日
You are doing good things. Thank you.
Star Strider
Star Strider 2020 年 9 月 13 日
I very much appreciate your compliment!
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by