Round the elements column of the matrix to the same digit than it is in the other column
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Laszlo Sleisz
el 14 de Jul. de 2021
Respondida: Stephen23
el 15 de Jul. de 2021
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 comentarios
Respuesta aceptada
Matt J
el 14 de Jul. de 2021
Editada: Matt J
el 14 de Jul. de 2021
One way,
Result(:,5) = round(Result(:,5),2,'significant');
numDigits=strlength(extractAfter(string(Result(:,5)),'.'));
numDigits(isnan(numDigits))=0
7 comentarios
Matt J
el 14 de Jul. de 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.
Más respuestas (1)
Stephen23
el 15 de Jul. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!