How to print 0 without a negative sign in the front? Everytime I want to print 0 it prints -0.000.

6 views (last 30 days)
1.0000 0 -0.0000 0 2.0000
0 1.0000 0.0000 0 0
0 0 1.0000 0 6.0000
0 0 -0.0000 1.0000 5.0000
I used format rat at first but then it made my 0's into astericks so then I tried format short which showed me that my error was in the zeros printing as 0.0000 and -0.0000. Could someone please tell me how to get rid of both -0.0000 and 0.0000 and replaced with just a 0.

Answers (1)

John D'Errico
John D'Errico on 12 Jun 2021
Edited: John D'Errico on 12 Jun 2021
That minus zero is NOT truly zero. It is just a tiny number that is slightly less than zero, but when rounded to only 4 digits for display, it "looks" like a zero.
format short
A = [1 0 -1e-6 0 2;0 1 1e-6 0 0]
A = 2×5
1.0000 0 -0.0000 0 2.0000 0 1.0000 0.0000 0 0
As you can see, in the third column, when I used format short, the numbers are shown as -0.0000 and 0.0000, even though they are not zero in either case.
If I use a better format, such as short g or long g, the approximate zeros are now seen to be just small numbers.
format short g
A
A = 2×5
1 0 -1e-06 0 2 0 1 1e-06 0 0

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!