TEXTSCAN Reads from Fortran Output - Precision Problem
1 view (last 30 days)
Show older comments
I am reading the output data from a fortran generated file which is in the form
720. 2.715E+12 4.437E+10
730. 2.342E+12 3.849E+10
.
.
.
2700. 5.282E+01 1.852E+03
2710. 4.882E+01 9.521E+03
when I use the texscan as:
FormatSpec='%f %f %f'
cell=textscan(fileID,FormatSpec,N)
First column loads with no problem but MATLAB stores the last lines values for 2nd and 3rd column as zero. for instance for the 2nd column output is:
1.0e+12 *
2.7150
2.3420
.
.
.
0.0000
0.0000
and similar output for the 3rd column. Is there any way to tell MATLAB to store the data as they are(i.e. with the same format as they are read).
Thanks
The fortran format of the data for 2nd and 3rd columns is "1P5E9.2".
0 Comments
Accepted Answer
Chris Turnes
on 4 Aug 2014
By default, MATLAB is displaying the numbers in the short format. As a result, while it may appear from the display that these numbers are zero, they are probably read in correctly. To test this, you can change the format of the display (see the documentation on format ).
For instance, using the four lines of the file that you provided, as well as your textscan command, if the format is changed to shortG the Command Window will show that these numbers are non-zero:
>> format shortG;
>> cell{2}
ans =
2.715e+12
2.342e+12
52.82
48.82
This confirms that MATLAB is indeed storing the data properly, it is just not being displayed in a meaningful way. To get a format closer to that of your file, you could also use the format shortE:
>> format shortE;
>> cell{2}
ans =
2.7150e+12
2.3420e+12
5.2820e+01
4.8820e+01
0 Comments
More Answers (0)
See Also
Categories
Find more on Fortran with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!