how to stop exponential notation, both in output and in variable editor

1.357 visualizaciones (últimos 30 días)
Hi is there any way, preferably from code, to stop exponential notation.
So any figures I display, or look at in the variable editor, are always in the format 0.0000000234 etc never 2.34e-8
Thanks for any help,
Tom
  3 comentarios
Walter Roberson
Walter Roberson el 6 de Jun. de 2018
No; if you have a need like that you should probably fprintf() the data
Walter Roberson
Walter Roberson el 17 de Dic. de 2019
Brando:
You could write a disp_no_scientific function that queried the existing format setting, and activated g format, and then returned to the previous format. However, as noted by Titus, format g does use scientific notation for sufficiently large or small values. There is no format setting for fixed point. If you need that then you should be using fprintf() or perhaps num2str() with an appropriate % format.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Dic. de 2011
Editada: John Kelly el 4 de Jun. de 2014
For variables that you disp(), command
format long
or
format long g
  5 comentarios
Sam H
Sam H el 14 de Mzo. de 2018
yes, you can use 'fprintf'
a=0.0001234;
fprintf('%.7f\n',a)
Walter Roberson
Walter Roberson el 17 de Dic. de 2019
Brando:
You could write a disp_no_scientific function that queried the existing format setting, and activated g format, and then returned to the previous format. However, as noted by Titus, format g does use scientific notation for sufficiently large or small values. There is no format setting for fixed point. If you need that then you should be using fprintf() or perhaps num2str() with an appropriate % format.

Iniciar sesión para comentar.

Más respuestas (3)

Titus Edelhofer
Titus Edelhofer el 7 de Dic. de 2011
Hi Tom,
as far as I know there is no way to force MATLAB to always use fixed notion. For generating output you can use fprintf with %f to use fixed notion.
Titus
  3 comentarios
Lars Abrahamsson
Lars Abrahamsson el 24 de Oct. de 2023
This answer is the most useful I think.

Iniciar sesión para comentar.


Deepan J
Deepan J el 27 de Sept. de 2018
format long g
  4 comentarios

Iniciar sesión para comentar.


SOREL
SOREL el 6 de Jun. de 2018
Editada: Walter Roberson el 6 de Jun. de 2018
Hi with the live editor I got a resul printed like this
A = 1.6050541506550198034773572941784e-40*d2
since 1.6e-40 is 0 is it possible to force the the A variable to be 0
  4 comentarios
Walter Roberson
Walter Roberson el 17 de Dic. de 2019
Note: there are additional new and quite obscure possibilities since R2019a. They are difficult to locate; if you do not already know they exist you are unlikely to find reference to them, and even if you know the exist you need a fair bit of experience with symbolic toolbox programming to make use of them :(
Steven Lord
Steven Lord el 24 de Oct. de 2023
FYI if you're doing numerical calculations involving trigonometric functions multiples of pi and want to avoid the round-off error caused by the pi function not returning the exact transcendental value of π, use the sinpi or cospi functions instead.
y = cos(pi/2)
y = 6.1232e-17
z = cospi(1/2)
z = 0

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by