Print number as .0000000E+00

I would like to print a number with the following format:
.0000000E+00
MATLAB prefers the following:
0.0000000E+000
Is there a way to solve this issue?

 채택된 답변

Jan
Jan 2013년 6월 18일

0 개 추천

댓글 수: 2

Hamilton
Hamilton 2013년 6월 19일
This is helpful removing the leading zero. Is there a way to maintain the exponential format? I think i can take care of the E+000 to E+00 issue by simply using some string modification functions.
Perhaps something like this:
char(java.text.DecimalFormat('#,##0.###E00').format(0.1));

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

추가 답변 (1개)

Pourya Alinezhad
Pourya Alinezhad 2013년 6월 18일

0 개 추천

fprintf('%1.5s',0.1)
1.5 stands for 5 decimal places.1 is for full number.
s==scientific
you could easily find a way to this problem if you were a c proogrammer...

댓글 수: 3

Jan
Jan 2013년 6월 18일
편집: Jan 2013년 6월 18일
No, according to the documentation '%s' means 'string', not 'scientific'. I assume you mean '%e' for the scientific notation.
But to my surprise the output is exactly the same (tested under 2009a, 2011b). This means that '%s' has the undocumented feature to act like '%e' when it gets numbers as input. Strange.
Anyhow, Hamilton asks for an omitted leading zero and a 2 digit exponent. While the first is ugly and provokes unexpected errors, such that it will hopefully not implemented, the second is the default in non-PC versions of Matlab and in the newest release R2013a.
Pourya Alinezhad
Pourya Alinezhad 2013년 6월 18일
actually i didn't checked this code in matlab.i used to code in this way in turbo c.and i per-assumed that this is true in matlab :)
Jan
Jan 2013년 6월 19일
@Pourya: And obviously your assumption is not really wrong. Thanks for this interesting new piece of information.
Of course TMW did not implement fprintf from scratch but relies on existing libraries. Therefore even known bugs like buffer overflows and other undocumented features like %s with numbers appear in Matlab.

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

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2013년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by