How to change values to 3 decimal points and 7 significant figures?

조회 수: 9 (최근 30일)
Loh Yang Yau
Loh Yang Yau 2021년 4월 11일
댓글: Loh Yang Yau 2021년 4월 15일
hi,
I am Matlab program beginner.
I came across a problem in which I want to change the decimal places and significant figues of the value I computed.
The values I get is
easting_northing =
1.0e+03 *
1.0000 1.0000
1.0635 0.9227
but actually I need the values to become like this form:
easting_northing =
1000.000 1000.000
1063.500 922.720
how to do that???
thank you in advance
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2021년 4월 11일
편집: Dyuman Joshi 2021년 4월 11일
You can use
format short g %you can also long, whatever you like
before the code, however this will return
[1000 1000; 1063.5 922.7], not exactly the output you want

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

채택된 답변

dpb
dpb 2021년 4월 11일
편집: dpb 2021년 4월 11일
You can't set an arbitrary format string or precision for command window output; only the few selectable choices given by the format command.
If you want/need a specific format, you have to output the data with a format string via fprintf or num2str or the like:
>> easting_northing =[1000,1000;1063.5,922.72]
easting_northing =
1.0e+03 *
1.0000 1.0000
1.0635 0.9227
>> fprintf('%10.4f %10.4f\n',easting_northing')
1000.0000 1000.0000
1063.5000 922.7200
>>
NB: Newcomers often get confused and mistake the limited number of significant digits shown at command window with the precision of the data itself -- note the display format does not in any way affect the internal storage precision that remains at full double precision. That doesn't seem to be the case here, but thought worth mentioning for any who may stumble upon the thread later...
  댓글 수: 3
dpb
dpb 2021년 4월 11일
And, of course, rereading the Q? title and noting the actual "need" example, the result with three instead of four decimal places is
>> fprintf('%10.3f %10.3f\n',easting_northing')
1000.000 1000.000
1063.500 922.720
>>
?)
Loh Yang Yau
Loh Yang Yau 2021년 4월 15일
thanks mate , thanks for ur help

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by