1234.5 instead of 1.2345e+03

조회 수: 7 (최근 30일)
Ganesh
Ganesh 2012년 7월 6일
When I read a variable from Excel with value say, 1234.5, Matlab reads in as 1.2345e+03. Instead I want the original format to be preserved (ie., it should stay as it is say, 1234.5 in this example). I have tried "format short g" etc, but these deal with number of digits after the decimal. How can I set the correct format? Thanks, Ganesh
  댓글 수: 1
Jan
Jan 2012년 7월 7일
Internally 1234.5 and 1.2345e+03 are the same numbers. The different notation concerns only the output to the command windows. Therefore it is necessary that you post more relevant details of your problem.

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

답변 (3개)

the cyclist
the cyclist 2012년 7월 6일
편집: the cyclist 2012년 7월 6일
It depends on the context of where you want this number displayed, but here is one way to show this number the way you want:
x = 1234.5;
sprintf('%5.1f',x)

Ganesh
Ganesh 2012년 7월 6일
Thanks for your reply. However, I donot want it displayed on the screen. I am using the variable as an input for a curve-fitting function "fitcurvedemo(xdata, ydata)". This function call does not seem to work if the variable is in scientific/engineering notation.
Thanks again, Ganesh
  댓글 수: 2
the cyclist
the cyclist 2012년 7월 6일
In MATLAB-speak, the "format" generally refers to how the variables are displayed, not to how they are stored internally, or used for computation.
Can you confirm that your variable xdata and ydata are being imported as numeric arrays, and not as text? That could be the problem. Are you able to post a small snippet of self-contained code that exhibits the problem?
Jan
Jan 2012년 7월 7일
@Ganesh: Please do not post comments as answers.

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


Ganesh
Ganesh 2012년 7월 6일
Nice idea. As such when the value of the input variable is <1000 (3 or less # digits before the decimal), the function call works. When the value of the variable gets >1000, it is read in the scientific format (like e+003) and this is when the function call does not work well.
Thanks in advance, Ganesh
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 7월 6일
What evidence do you see that the fitcurvedemo call is not working?
Does the issue only affect the xdata, or only affect the ydata ? For example if you were to divide the ydata by 10 so that it remained less than 1000, does that work?

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

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by