- #1
madtraveller
- 28
- 0
Homework Statement
I have to read a text file with fixed format as follows
The first column is supposed to be year, 2nd is month and 3rd is day
The file has following format: 4d 2d 2d f9.4 f9.4 f9.4 f9.4 4d 4d 4d 4d 4d 4d
Code:
2000 218 0.4546 0.2394 0.0761 0.1167 55 58 1 1 1 1
2000 226 -9.9999 -9.9999 0.3701 0.7276 -99 -99 100 100 100 100
2000 3 5 0.4571 0.2612 0.3657 0.8069 54 56 100 100 100 100
2000 313 -9.9999 -9.9999 0.3310 0.7816 -99 -99 100 100 100 100
2000 321 0.5156 0.2806 0.3777 0.8762 56 56 97 97 98 98
2000 329 -9.9999 -9.9999 0.4171 1.0047 -99 -99 100 100 100 100
2000 4 6 0.5190 0.3154 0.4273 1.0269 58 54 100 100 100 100
2000 414 -9.9999 -9.9999 0.4521 1.1319 -99 -99 100 100 100 100
2000 422 0.5845 0.3109 0.4627 1.1363 56 56 100 100 100 100
Homework Equations
The Attempt at a Solution
I tried to use textscan or fscanf but it just didn't work. The program always had problem with the first 3 column
E.g.
Code:
clc
clear all
fid = fopen('data.txt','r');
data1 = fscanf(fid, '%4d %2d %2d %9.4f %9.4f %9.4f %9.4f %4d %4d %4d %4d %4d %4d')
data2 = fscanf(fid, '%d %d %f %f %f %f %d %d %d %d %d %d')
data3 = fscanf(fid, '%4d%2d%2d%9.4f%9.4f%9.4f%9.4f%4d%4d%4d%4d%4d%4d')
fclose(fid);
Plz suggest me with a better solutions. Thank you very much
madtraveller