Why does FPRINTF put minus signs in front of zeros in my file?
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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.
Risposta accettata
  MathWorks Support Team
    
 il 22 Gen 2010
        This is a result of 0 and -0 having different IEEE representations. The following example MATLAB code illustrates this difference:
>> format hex
>> [0 -0]
 ans =
    0000000000000000   8000000000000000
When MATLAB calls FPRINTF, MATLAB actually calls a C routine which treats them differently. However, despite this difference, MATLAB treats 0 and -0 the same in all calculations (ie. 0 == -0). Therefore you can work around this behavior by replacing '-0' with 0 in MATLAB, as shown in the following example:
m = [0 -0]
fprintf(1,'m = [%1.2f %1.2f]\n',m)
m(m==0) = 0
fprintf(1,'m = [%1.2f %1.2f]\n',m)
 m =
      0     0
 m = [0.00 -0.00]
 m =
      0     0
 m = [0.00 0.00]
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Logical in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
