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

3 vues (au cours des 30 derniers jours)
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 commentaires
Stephen23
Stephen23 le 11 Fév 2020
"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 le 11 Fév 2020
Since your data is well formated, could it be easier using a table?

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 11 Fév 2020
Modifié(e) : Stephen23 le 12 Fév 2020
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.

Community Treasure Hunt

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

Start Hunting!

Translated by