How to format numbers in exponential notation with base 1e3

10 ビュー (過去 30 日間)
Julian Schäfer
Julian Schäfer 2020 年 10 月 6 日
回答済み: Star Strider 2020 年 10 月 6 日
Hi,
I want to format numbers to a exponential notation with the base 1e3.
For example I have a vector a:
a = [25.12; 67.29; 120.00; 256.65; 501.58; 1366.26];
All numbers should have the same 5 digits with a precision of 4 in exponential notation with the base 1e3. So the output should be:
b = 1e3 * [0.0251 0.0673 0.1200 0.2567 0.5016 1.3663];
Does anybody know how to do this?
Thanks!

採用された回答

Star Strider
Star Strider 2020 年 10 月 6 日
This will correctly calculate tha mantissas:
rfxm = @(x,xpnt) [sign(x).*10.^(log10(abs(x))-xpnt)]; % Anonymous Function Creating Reformatted Number
so:
a = [25.12; 67.29; 120.00; 256.65; 501.58; 1366.26];
xpnt = +3;
Out = rfxm(a,xpnt)
produces:
Out =
0.0251
0.0673
0.1200
0.2567
0.5016
1.3663
This is as close as I can get to your desired output:
Out = [sprintf('1e%d * [',xpnt) sprintf('%.4f\t', rfxm(a.',xpnt)) ']']
.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by