Why does FPRINTF put minus signs in front of zeros in my file?

4 views (last 30 days)
Why does FPRINTF put minus signs in front of zeros in my file?
MATLAB states that these values are really zero, so it's not a round off error.
How can I get around this? I have a matrix of zeros and when they are multiplied by a negative number and printed, the results turn out to be zeros with a negative sign in front of it.
Also, how would I be able to change just the zeros in a matrix with zero and nonzero elements?

Answers (1)

Walter Roberson
Walter Roberson on 3 Jul 2012
The numbers are not really 0 then. The only way to get MATLAB to "state that these values are really zero" is to test them for equality for zero. If you are relying upon the fact that disp() of the value shows up as 0.0000 then MATLAB has not stated that they are zero, only that to 4 digits they round to 0. Use
format long g
to get a better idea of actual values.
And try num2hex() on the value: num2hex() of 0 is always 0000000000000000 but num2hex() of a non-zero value will never show up that way. For example,
>> num2hex(1e-308)
ans =
000730d67819e8d2

Community Treasure Hunt

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

Start Hunting!