Error using textscan Mismatch between file and format character vector. Trouble reading 'Numeric' field from file (row number 1, field number 3)

4 ビュー (過去 30 日間)
I get the following error:
Error in Ti2_Auto_9_20x_USE_addedcode (line 11)
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError',
false);
Error using textscan
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 3) ==>
t1xy10z12.tif,33,255,255,9.91277508,4.23866220,34.77334951,0.59568542,100,2.33865654,0.42759592,0.74157303\n
From this code:
for i = 1:length(list)-2
filename = list(i+2,1).name;
delimiter = ',';
startRow = 2;
formatSpec = '%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
tem = [];
for n = 1:12
tem(:,n) = dataArray{1,n};
end
Here is the first .csv file being read/errored on (also attached):
Any help to resolve this is appreciated!
  2 件のコメント
Stephen23
Stephen23 2020 年 2 月 11 日
"Here is the first .csv file being read/errored on:"
We can't do much with a screenshot. Please upload the actual CSV file by clicking the paperclip button.
Hank
Hank 2020 年 2 月 11 日
Since your data is well formated, could it be easier using a table?

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2020 年 2 月 11 日
編集済み: Stephen23 2020 年 2 月 12 日
The second field is clearly not numeric, containing values like
020520t1xy10z12.tif
020520t1xy10z12.tif
020520t1xy10z12.tif
020520t1xy10z12.tif
020520t1xy10z12.tif
020520t1xy10z12.tif
etc.
so you will need to import it as character, eg:
formatSpec = '%f%s%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
% ^^ second field as character
Tip: simply use the CollectOutputs option rather than that inefficient loop at the end of your code.

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by