MATLAB Answers

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

조회 수: 37(최근 30일)
Loh Yang Yau
Loh Yang Yau 11 Apr 2021 10:51
댓글: Loh Yang Yau 15 Apr 2021 2:24
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

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

채택된 답변

dpb 11 Apr 2021 13:55
편집: dpb 11 Apr 2021 13:58
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
Loh Yang Yau
Loh Yang Yau 15 Apr 2021 2:24
thanks mate , thanks for ur help

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by