Format of exponential with num2str
19 次查看(过去 30 天)
显示 更早的评论
Hello everybody,
I have a problem and I need some help.
I have something like this :
num2str(2.55, '1.3e') and this gives me
2.550e+000
With 1 for the field width and 3 for the precision after the decimal point.
What I want is this :
2.550+e00
Only 2 zeros for the exponential. Is there a way to do this?
Thank you.
0 个评论
采纳的回答
Walter Roberson
2013-2-20
The exponential format differs between MS Windows and the other operating systems.
You can use one of the other operating systems. Or, you can manipulate the returned strings to delete the extra 0. There is no format item to control the number of digits in the exponential.
1 个评论
Walter Roberson
2013-2-21
S = num2str(2.55, '1.3e');
S = regexprep( S, '(?<=e[-+])0', '' );
更多回答(4 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!