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

9 visualizaciones (últimos 30 días)
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 comentarios
Dyuman Joshi
Dyuman Joshi el 11 de Abr. de 2021
Editada: Dyuman Joshi el 11 de Abr. de 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

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 11 de Abr. de 2021
Editada: dpb el 11 de Abr. de 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 comentarios
dpb
dpb el 11 de Abr. de 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
>>
?)
Loh Yang Yau
Loh Yang Yau el 15 de Abr. de 2021
thanks mate , thanks for ur help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by