Mokujin
Mokujin

Reputation: 65

Rounding off of values in matlab

I have some values which are close to zero, and when i run my code, MATLAB rounds off these values to zero.

e.g

initial_values = 0.01 0.0002 0.03 0.0004....

after running code these values (0.0002 and 0.0004) become zero

initial_values = 0.01 0 0.03 0

I there some way to prevent this from happening because I need the actual values.

Upvotes: 0

Views: 1300

Answers (2)

claudiop
claudiop

Reputation: 140

Declare at the beginning of your code that you want to use the format long g:

format long g

In this way the numbers will be displayed in the more readable way between fixed or floating point.

With format long you will have:

initial_values =   0.010000000000000   0.000200000000000   
                   0.030000000000000   0.000400000000000

With format long g:

initial_values =   0.01  0.0002 0.03 0.0004

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112659

Perhaps it's just a displaying issue. Try format long in the command window

Upvotes: 1

Related Questions