Turning a 1x3 vector into a three digit number

3 visualizaciones (últimos 30 días)
Aday Gabriel
Aday Gabriel el 26 de Oct. de 2022
Respondida: Voss el 26 de Oct. de 2022
Hi, i have a 1x3 vector and I want to turn it into a three digit number (turning each element of the vector into one of the digits). So, for example v=[1 0 0] would be converted into 100, or w=[9 0 9] would be 909.
Is this possible?
I made a programm that shows all the numbers from 100 to 999 that start and end with the same number using 1x3 vectors, and now I want to manipulate them asif they were three digit numbers (to add them, know the average value, etc.).
Btw, the "contar" part is to count how many of these numbers (well, in my case vectors) exist in said interval.
Thanks a lot in advance. :)

Respuestas (1)

Voss
Voss el 26 de Oct. de 2022
v = [1 5 6];
sum(v.*10.^(2:-1:0))
ans = 156
% or
polyval(v,10)
ans = 156

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by