Round the elements column of the matrix to the same digit than it is in the other column
조회 수: 3 (최근 30일)
이전 댓글 표시
I round elements one of column of matrix to 2 significant digits:
Result(:,5) = round(Result(:,5),2,'significant');
I wold like to round the elements another column of the same matrix to exactly same digits than it is in 'significant' digit column.
Is there any way to read back the number of digits from the 'significant' digit column to use it in other column?
댓글 수: 0
채택된 답변
Matt J
2021년 7월 14일
편집: Matt J
2021년 7월 14일
One way,
Result(:,5) = round(Result(:,5),2,'significant');
numDigits=strlength(extractAfter(string(Result(:,5)),'.'));
numDigits(isnan(numDigits))=0
댓글 수: 7
Matt J
2021년 7월 14일
Thank you, now it works.
You are welcome, but please Accept-click the answer to indicate so.
Is it possible to format the number to N digits to the right of the decimal point, delete the unnecessary zeros.
Only if the array is converted to a string. If you plan to work with Result as numeric data, the only control you have over how it is displayed is through the format() command.
추가 답변 (1개)
Stephen23
2021년 7월 15일
S = 2;
A = 32*rand(5,7)-13
round(A(:,5),S,'significant') % for comparison
P = S-1-floor(log10(abs(A(:,5))));
B = round(A.*10.^P)./(10.^P)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!