Delimiter for csv format

6 次查看(过去 30 天)
Sérgio Querido
Sérgio Querido 2017-8-9
回答: Jan 2017-8-9
I did a matlab code for transform csv files to organized table in a xls file (by delimiter). The Problem:
Error using textscan
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1, field number 2) ==>
Xavi,3237.531009,2083.298925,501.542962,404.082872,162.895678,85.710573,121,1,89,7,8,26.156520,4.672901\n
Error in GPS_import_AFA (line 41)
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue'
,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
Error in delimitar_dados_gps_csv (line 28)
data=GPS_import_AFA(Filename,2);

回答(1 个)

Jan
Jan 2017-8-9
It is a strange method to read a file line by line by frewind-ing it in each iteration. It would be much cheapter to import the file at once and perfomr the sorting afterwards. Note that the disk access is 1000 times slower than accessing the data in the RAM.
The
formatSpec = '%f%f%f%f%f%f%f%*s%*s%*s%[^\n\r]';
and the data:
20170730,Xavi,3237.531009,2083.298925,501.542962,404.082872,162.895678,85.710573,121,1,89,7,8,26.156520,4.672901
do not match: As the error message tells clearly already, the 2nd input is not a number. What about:
formatSpec = '%f%s%f%f%f%f%f%*s%*s%*s%[^\n\r]';

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by