how to stop exponential notation, both in output and in variable editor
조회 수: 1,930 (최근 30일)
이전 댓글 표시
Hi is there any way, preferably from code, to stop exponential notation.
So any figures I display, or look at in the variable editor, are always in the format 0.0000000234 etc never 2.34e-8
Thanks for any help,
Tom
댓글 수: 3
Walter Roberson
2019년 12월 17일
Brando:
You could write a disp_no_scientific function that queried the existing format setting, and activated g format, and then returned to the previous format. However, as noted by Titus, format g does use scientific notation for sufficiently large or small values. There is no format setting for fixed point. If you need that then you should be using fprintf() or perhaps num2str() with an appropriate % format.
채택된 답변
Walter Roberson
2011년 12월 7일
편집: John Kelly
2014년 6월 4일
For variables that you disp(), command
format long
or
format long g
For the variable editor, see these instructions: http://www.mathworks.com/help/matlab/matlab_prog/check-variable-scope-in-editor.html
댓글 수: 5
Walter Roberson
2019년 12월 17일
Brando:
You could write a disp_no_scientific function that queried the existing format setting, and activated g format, and then returned to the previous format. However, as noted by Titus, format g does use scientific notation for sufficiently large or small values. There is no format setting for fixed point. If you need that then you should be using fprintf() or perhaps num2str() with an appropriate % format.
추가 답변 (3개)
Titus Edelhofer
2011년 12월 7일
Hi Tom,
as far as I know there is no way to force MATLAB to always use fixed notion. For generating output you can use fprintf with %f to use fixed notion.
Titus
댓글 수: 2
SOREL
2018년 6월 6일
편집: Walter Roberson
2018년 6월 6일
Hi with the live editor I got a resul printed like this
A = 1.6050541506550198034773572941784e-40*d2
since 1.6e-40 is 0 is it possible to force the the A variable to be 0
댓글 수: 4
Walter Roberson
2019년 12월 17일
Note: there are additional new and quite obscure possibilities since R2019a. They are difficult to locate; if you do not already know they exist you are unlikely to find reference to them, and even if you know the exist you need a fair bit of experience with symbolic toolbox programming to make use of them :(
Steven Lord
2023년 10월 24일
FYI if you're doing numerical calculations involving trigonometric functions multiples of pi and want to avoid the round-off error caused by the pi function not returning the exact transcendental value of π, use the sinpi or cospi functions instead.
y = cos(pi/2)
z = cospi(1/2)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!