0

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
    This is a formatting issue. See help format for how to choose between floating and fixed point output formats. Also, an internet search will explain the difference between the two. Look for the difference between %f, %g, and %e when printing. – AnonSubmitter85 Jul 08 '15 at 17:08

2 Answers2

1

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$$

Robert Israel
  • 448,999
1

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.

Scounged
  • 937
  • Tried that. It works, but NOT for the third column. – India Slaver Jul 08 '15 at 06:48
  • Really? It worked when I tested it. What do you get in the third column? – Scounged Jul 08 '15 at 06:51
  • For me the third column displays only this.

    0.000000000000000 0.000000000000000 -0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 0.000000000000000 0.000000000000000

    – India Slaver Jul 08 '15 at 06:55
  • That is actually really strange. Especially since you didn't get that result at first, when you didn't use format long;. To be honest, I have no idea why it wouldn't work. – Scounged Jul 08 '15 at 07:03