Reading .dat csv like file in Matlab
Show older comments
Hey guys!
I need some help reading a .dat file in MATLAB (as an array).
The content of the file (if I open it with notepad) is like this
"TOA5","CR800Series","CR800","36460","CR800.Std.28","CPU:HAC.CR8","48946","HAC_Meteo_Data_05"
"TIMESTAMP","RECORD","Anonymous1","Anonymous2","Tair_Avg","Tair_Std","RH_Avg","RH_Std","SolRad_Avg","SolRad_Std","AcVirTemp_Avg","AcVirTemp_Std","WV_XYZ_Avg","WV_XYZ_Std","WD_Elev_Avg","WD_Elev_Std","WD_Azim_Avg","WD_Azim_Std","WV_Azim_Avg","WV_Azim_Std","WV_X_Avg","WV_X_Std","WV_Y_Avg","WV_Y_Std","WV_Z_Avg","WV_Z_Std","PTemp","batt_volt_Min"
"TS","RN","","","deg_Celsiou","deg_Celsiou","%","%","W/m2","W/m2","","","","","","","","","","","","","","","","","",""
"","","Smp","Smp","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Avg","Std","Smp","Min"
"2016-05-21 04:05:00",9825,105,711,3.93,0.014,100,0,"NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN",23.01,13.87
"2016-05-21 04:10:00",9826,105,711,3.934,0.018,100,0,"NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN","NAN",23.01,13.87
There are many more lines underneath and I don't really need the first few ones. All I need is to have the numbers in their cells. When I use Excel or Libre Office to open the file, it opens without the commas or the quotes etc.
What would be the best way to read the file? I found some way, but I am missing something to make it work properly :
f= fopen('x.dat');
data=fread(f);
fclose(f);
y = importdata('x.csv') %I converted my .dat to a .csv and that worked well, but I really need it to read from the .dat file
fIDF=fopen(nameFile);
NephtDataAr0= textscan(fIDF, '%s %f %f %f %f %f %f %f %f %f %f %f %s %s','Delimiter',',','CommentStyle','[');
fclose(fIDF); %Someone that has written a program to read some similar data from a .txt file, used the line above. Could that be of any use?
filename = 'csvlist.dat';
M = csvread(filename) %I found this one but I am getting this error
Error using dlmread (line 147)
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==>
"TOA5","CR800Series","CR800","36460","CR800.Std.28","CPU:HAC.CR8","48946","HAC_Meteo_Data_05"\n
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
Error in readfile2 (line 2)
M = csvread(filename)
Thanks a lot for your time!
Accepted Answer
More Answers (1)
asdada
on 24 Oct 2016
0 votes
Categories
Find more on Large Files and Big Data 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!