Round the elements column of the matrix to the same digit than it is in the other column
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Matt J
il 14 Lug 2021
Modificato: Matt J
il 14 Lug 2021
One way,
Result(:,5) = round(Result(:,5),2,'significant');
numDigits=strlength(extractAfter(string(Result(:,5)),'.'));
numDigits(isnan(numDigits))=0
7 Commenti
Matt J
il 14 Lug 2021
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.
Più risposte (1)
Stephen23
il 15 Lug 2021
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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!