Azzera filtri
Azzera filtri

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

6 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

John D'Errico
John D'Errico il 12 Giu 2021
Modificato: John D'Errico il 12 Giu 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

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by