Using sign(x) with -0.00?

18 visualizaciones (últimos 30 días)
Martin
Martin el 31 de En. de 2013
Hi, I need to go through a vector and check the sign of an oscillatory function but I have a lot of -0.0000's at the start which is going to mess up what I need to do.
Is there anyway to convert them to 0.000 rather than -0.000?
Thanks

Respuesta aceptada

Jan
Jan el 31 de En. de 2013
Editada: Jan el 31 de En. de 2013
Matlab does not have a -0.0, therefore what you are seeing must be a -0.000000000000001 or similar, which is hidden by the display format. To see more digits type this in the command window:
format long g
If you have good reasons to claim, that these data are pure noise, you can smooth it:
x(abs(x) < 1e-10) = 0.0;
But be sure to note the physical motivation of the threshold value.
  5 comentarios
Jan
Jan el 31 de En. de 2013
Or to explain "best": the "e" notation is used, when it can display more significant digits than the 0.0000xyz notation.
James Tursa
James Tursa el 31 de En. de 2013
Editada: James Tursa el 31 de En. de 2013
To clarify what Jan wrote, IEEE double and single floating point (which MATLAB uses) do in fact have distinct -0.0 bit representations (sign bit set to 1 and all other bits reset to 0) that is different from 0.0 (all bits reset to 0). But by default MATLAB will not display the minus sign '-' for these numbers, so when you see something like -0.0000 printed to the screen it is not really a -0.0 value. Rather it represents a small negative number compared to the other numbers that were printed to the screen at the same time (there simply weren't enough digits printed to show the non-zero digits of the small negative number). To see this type the following at the MATLAB prompt:
format hex
0
-0
0 == -0
typecast(0,'uint64') == typecast(-0,'uint64')

Iniciar sesión para comentar.

Más respuestas (1)

José-Luis
José-Luis el 31 de En. de 2013
your_mat(abs(your_mat) < 100*eps) = 0; %or some other limit
  1 comentario
Martin
Martin el 31 de En. de 2013
This looks like a good thing to do also, thanks. For all intents and purposes the numbers I am getting -0.00000 for could be equated to zero.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by