Turning all elements of a column array into the same factor of 10

2 visualizaciones (últimos 30 días)
I have an array that looks like this:
X=[19.9 20 20 20.1 20.12 19.81 20 20 20 ... ]
So it is predomintantly an integer factor of 10 (but naturally I don't know in advance what is). What is the easiest way to turn all of the numbers into 20 (or any factor of 10)?

Respuesta aceptada

Image Analyst
Image Analyst el 20 de Ag. de 2023
Editada: Image Analyst el 20 de Ag. de 2023
Try round
X = [19.9, 20, 20, 20.1, 20.12, 19.81, 20, 32, 46];
rounded = round(X, -1)
rounded = 1×9
20 20 20 20 20 20 20 30 50

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by