필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by