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

9 Ansichten (letzte 30 Tage)
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 11 Apr. 2021
Bearbeitet: Dyuman Joshi am 11 Apr. 2021
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 11 Apr. 2021
Bearbeitet: dpb am 11 Apr. 2021
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 Kommentare
dpb
dpb am 11 Apr. 2021
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
>>
?)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by