Reputation: 179
I want to read this file in MATLAB, the file contains these data
1/1/2008 1110 98.5
1/2/2008 1110 99.5
1/3/2008 1110 96.5
1/4/2008 1110 32.5
1/5/2008 1110 8.56
1/6/2008 1110 48.5
it should be in five columns:
Upvotes: 1
Views: 7089
Reputation: 124563
Use the TEXTSCAN function:
%# parse file (change the data types if necessary)
fid = fopen('file.dat','rt');
C = textscan(fid, '%d/%d/%d %d %f', 'Delimiter',' ');
fclose(fid);
%# put columns in separate variables
[dt_month,dt_day,dt_year,val1,val2] = deal(C{:});
%# convert to serial date
dt = datenum(double(dt_year),double(dt_month),double(dt_day));
Upvotes: 5