Reading a CSV ... problems

1 次查看(过去 30 天)
Adam Klingest
Adam Klingest 2015-3-9
Hi
I have a .csv file in the following format:
SimpleDB data file version 2.0
TIMESTAMP,mode_0[-],,state_0[-],,Run_0[h],,Feed_0[h],,gbkr_0[-],,bkrop_0[-],,Etot_0[kWh],,Eday_0[kWh],,Pac_0[kW],,Q_0[kVAr],,Iac_0[A],,Uac_0[V],,fac_0[Hz],,cphi_0[-],,Paclim_0[kW],,Qset_0[kVAr],,Pdc_0[kW],,Udc1_0[V],,Idc1_0[A],,Pdc1_0[kW],,Udc2_0[V],,Idc2_0[A],,Pdc2_0[kW],,Udc3_0[V],,Idc3_0[A],,Pdc3_0[kW],,Udc4_0[V],,Idc4_0[A],,Pdc4_0[kW],
1425254400002,???,AAG8/,0,AAG8/,NaN,AAG8/,NaN,AAG8/,false,AAG8/,0,AAG8/,NaN,AAG8/,0.000,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,10.000,AAG8/,0.000,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/
1425254401001,???,AAG8/,0,AAG8/......
It is a very big file, and as you can see contains a lot of NaN's and other strings. I have tried using csvread(), but it doesn't work. I get the
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1, field number 2) ==>
???,AAG8/,0,AAG8/,NaN,AAG8/,NaN,AAG8/,false,AAG8/,0,AAG8/,NaN,AAG8/,0.000,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,10.000,AAG8/,0.000,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,AAG8/,NaN,A...
I have also tried xlsread(), and it kind of works, but only on a computer with excel installd, and I need it to work on any computer. Does anybody know how I can effectively read such a file, and sort the data under the right header collumns?
Regards Adam

回答(1 个)

Michael Haderlein
Reading should be possible with textscan. You can define the format of the data columnwise. Does it help?

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by