Using the command num2str

5 次查看(过去 30 天)
Khalid Alsinan
Khalid Alsinan 2020-11-11
评论: Ameer Hamza 2020-11-11
When I run:
num2str(5.7831e-04)
I get: '0.00057831'
How can I obtain '5.7831e-04' instead?

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-11-11
Use sprintf()
sprintf('%.4e', 5.7831e-04)
  3 个评论
Khalid Alsinan
Khalid Alsinan 2020-11-11
Never mind! Thank you so much Ameer!!
Ameer Hamza
Ameer Hamza 2020-11-11
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by