Using the command num2str

When I run:
num2str(5.7831e-04)
I get: '0.00057831'
How can I obtain '5.7831e-04' instead?

Respuestas (1)

Ameer Hamza
Ameer Hamza el 11 de Nov. de 2020

1 voto

Use sprintf()
sprintf('%.4e', 5.7831e-04)

3 comentarios

Khalid Alsinan
Khalid Alsinan el 11 de Nov. de 2020
Thanks Ameer, but I don't want to display it.. I just want to store it. Is there another way other than sprintf?
Khalid Alsinan
Khalid Alsinan el 11 de Nov. de 2020
Never mind! Thank you so much Ameer!!
Ameer Hamza
Ameer Hamza el 11 de Nov. de 2020
Storing a number is not a matter of format. Inside memory, it will be saved as a double datatype with same bits. The format is only important if you want to print the number.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 11 de Nov. de 2020

Comentada:

el 11 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by