confusion about the format in MATLAB

the example in MATLAB Document is when the format is short,
>>x = [4/3 1.2345e-6]
x =
1.3333 0.0000
but when i input
>>x = 1.2345e-6
x =
1.2345e-06
why i cannot get the 0.0000?

 Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 7 Jul. 2019
Bearbeitet: KALYAN ACHARJYA am 7 Jul. 2019

0 Stimmen

Please note experts will answer on this. I am trying to give hints, its just compact display 0.0000 in command window, when it display along with large numbers, like 4/3, when it compare with itself.
Mustt Recommended to read Machine Precision of Matlab
>> format short
>> x=[4/3 1.2345e-6]
x =
1.3333 0.0000
>> x(2)
ans =
1.2345e-06
Please dont consider x(2) is 0, as you have seen in the upper example.
More example
>> a=0.0000000000000000001
a =
1.0000e-19
>> b=[1 0.00000000000001]
b =
1.0000 0.0000
>> b(2)==0
ans =
logical
0
It documentation says, display output in the short format (compact), what I relized after using Matlab is, the diaplay value may not be actual value, therefore be note on format of display. How the number display depends on other numbers and format. If it displays individual, there is no issue, but if you display small number with large number, such thing occured.
Members please do answer or comment, if you feel correction or more appropriate.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 7 Jul. 2019

0 Stimmen

format short does not mean 5 digits after the decimal place. format short takes the largest absolute value out of all of the values on the 2d plane and uses 5 digits for that, and everything else is scaled according to that.
The only format option for a fixed number of decimal places is format bank for 2 digits.

Produkte

Version

R2018a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by