フィルターのクリア

Want to truncate an array

3 ビュー (過去 30 日間)
Hemanta Hazarika
Hemanta Hazarika 2024 年 3 月 6 日
回答済み: Walter Roberson 2024 年 3 月 6 日
Suppose i have an array of [8.5766662529*10^22; 5.354353982*10^22;5.289634*10^22]. Now i want to truncate the array upto 4 decimal and power will remain same how i will do that?

回答 (2 件)

Walter Roberson
Walter Roberson 2024 年 3 月 6 日
format long g
A = [8.5766662529*10^22; 5.354353982*10^22;5.289634*10^22]
A = 3×1
1.0e+00 * 8.5766662529e+22 5.354353982e+22 5.289634e+22
round(A, 4, 'significant')
ans = 3×1
1.0e+00 * 8.577e+22 5.354e+22 5.29e+22

Star Strider
Star Strider 2024 年 3 月 6 日
There are a few options, including using the vpa function in the Symbolic Math Toolbox, and to use sprintf to display the values, that retain their full precision in the original code.
Another option is to use the format function however there are only a few options with it—
format longE
v = [8.5766662529*10^22; 5.354353982*10^22;5.289634*10^22]
v = 3x1
1.0e+00 * 8.576666252900000e+22 5.354353982000000e+22 5.289634000000001e+22
format shortE
v
v = 3x1
1.0e+00 * 8.5767e+22 5.3544e+22 5.2896e+22
format shortG
v
v = 3x1
1.0e+00 * 8.5767e+22 5.3544e+22 5.2896e+22
.

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by