How to change values to 3 decimal points and 7 significant figures?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
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
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
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
>>
?)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!