Losing out on precision when importing values from notepad to Matlab

68 Views Asked by At

Here is the notepad file which I am trying to import to Matlab.

0.0833333 -1.42876e-005 -6.8571e-024
0.166667 -2.86315e-005 3.59222e-023
0.25 -4.30324e-005 -3.44176e-023
0.333333 -5.7491e-005 7.89197e-023
0.416667 -7.2008e-005 2.58657e-022
0.5 -8.65841e-005 2.26725e-023
0.583333 -0.00010122 2.88135e-022
0.666667 -0.000115916 -3.11975e-022
0.75 -0.000130674 1.65466e-022
0.833333 -0.000145494 1.95335e-022

The Matlab Code that I am using to import it is

fid = fopen('ouput.out', 'r');
FC = textscan(fid, '%f %f %f', 10);
fclose(fid);

celldisp(FC);

Matlab Output

FC{1} =

    0.0833
    0.1667
    0.2500
    0.3333
    0.4167
    0.5000
    0.5833
    0.6667
    0.7500
    0.8333



FC{2} =

   1.0e-03 *

   -0.0143
   -0.0286
   -0.0430
   -0.0575
   -0.0720
   -0.0866
   -0.1012
   -0.1159
   -0.1307
   -0.1455



FC{3} =

   1.0e-21 *

   -0.0069
    0.0359
   -0.0344
    0.0789
    0.2587
    0.0227
    0.2881
   -0.3120
    0.1655
    0.1953

As can be seen, I am losing out on the precision as Matlab output restricts to only 4 digits after the decimal. How do I sort this out to direct the Matlab output as it is in the Notepad file?

2

There are 2 best solutions below

0
On

Matlab does not display all the digits it has. I don't think you've lost any precision. For example:

>> 1000000*FC{2}(1)

$$ -14.2876$$

4
On

It seems like what you want to do is add the line

format long;

in the beginning of the code, so that Matlab will display more decimal points than it does in default mode.