use sprintf while selecting exponential power

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 13 Set 2020
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 Commenti
Walter Williams
Walter Williams il 13 Set 2020
You are doing good things. Thank you.
Star Strider
Star Strider il 13 Set 2020
I very much appreciate your compliment!
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by