Borrar filtros
Borrar filtros

convert large number to smaller

8 visualizaciones (últimos 30 días)
Lieke Numan
Lieke Numan el 10 de Mayo de 2019
Comentada: Star Strider el 10 de Mayo de 2019
I have a large array with numbers like these:
3.2692e+17
However, I want to extraxt the first three numbers, as I am interested in the 32.6 (or 32.7 if rounded). Some numbers are 3.2692e+16 for example, so dividing by e+16 is not working. What is the easiest way to do this?
  1 comentario
KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Mayo de 2019
Editada: KALYAN ACHARJYA el 10 de Mayo de 2019
Input=3.2692e+17
Disired Result=32.6
You want convert or extract?

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 10 de Mayo de 2019
One approach:
f = @(x) round(x.*10.^floor(1-log10(abs(x))),2);
producing:
x = [3.2692e+17; 3.2692e+16; 4.2516E+8];
Result = f(x)
Result =
3.27
3.27
4.25
Change the last argument to the round function to change the number of decimal places the function returns.
  2 comentarios
Lieke Numan
Lieke Numan el 10 de Mayo de 2019
Thanks a lot!
Star Strider
Star Strider el 10 de Mayo de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion 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!

Translated by