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

9 visualizaciones (últimos 30 días)
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 comentarios
Stephen23
Stephen23 el 11 de Feb. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 11 de Feb. de 2020
Editada: Stephen23 el 12 de Feb. de 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.

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by