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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by