Format of exponential with num2str

조회 수: 6 (최근 30일)
Kov
Kov 2013년 2월 20일
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.

채택된 답변

Walter Roberson
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
Walter Roberson 2013년 2월 21일
S = num2str(2.55, '1.3e');
S = regexprep( S, '(?<=e[-+])0', '' );

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Kov
Kov 2013년 2월 21일
Thanks for the answer. Yeah I'm on Windows and I only have this operating system.
How can I manipulate the returned strings to remove the extra zero, knowing that it would be the first zero of the three for the exponential?

José-Luis
José-Luis 2013년 2월 21일

Kov
Kov 2013년 2월 21일
Thanks for the script.
I think i'll just manipulate the returned strings. Thanks for the help.

Daniel Shub
Daniel Shub 2013년 2월 21일

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by