use sprintf while selecting exponential power
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Walter Williams
le 13 Sep 2020
Commenté : Star Strider
le 13 Sep 2020
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
0 commentaires
Réponse acceptée
Star Strider
le 13 Sep 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 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!