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):![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/271058/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/271058/image.png)
Any help to resolve this is appreciated!
2 件のコメント
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.
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!