Delimiter for csv format

조회 수: 8 (최근 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에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by