Using sign(x) with -0.00?

조회 수: 18 (최근 30일)
Martin
Martin 2013년 1월 31일
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

채택된 답변

Jan
Jan 2013년 1월 31일
편집: Jan 2013년 1월 31일
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
Jan
Jan 2013년 1월 31일
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 2013년 1월 31일
편집: James Tursa 2013년 1월 31일
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')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

José-Luis
José-Luis 2013년 1월 31일
your_mat(abs(your_mat) < 100*eps) = 0; %or some other limit
  댓글 수: 1
Martin
Martin 2013년 1월 31일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by