Azzera filtri
Azzera filtri

Want to truncate an array

3 visualizzazioni (ultimi 30 giorni)
Hemanta Hazarika
Hemanta Hazarika il 6 Mar 2024
Risposto: Walter Roberson il 6 Mar 2024
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?

Risposte (2)

Walter Roberson
Walter Roberson il 6 Mar 2024
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 il 6 Mar 2024
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
.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by