How to locate character string in a csv file and skip it

I'm reading a csv file, however, somewhere in the file, (unknown location, so the row, column for this character), an unrecognizable or non-numeric character string (for example, Fö£a´]=Õê´‡X¼Ð, which is generated by binary to ascii conversion process) will be encountered, so the format specification in textscan cannot be used (because of the unknown location). So I saw the error in the following. Is there any way to use textscan or even csvread to process this kind of csv file, without compromising the speed? Many thanks.
"Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1096608,
field number 110) ==> Fö£a´]=Õê´‡X¼Ð , , , ,$, , , , , , , , ,
, , , , , , , , , , , , , , , \n
Error in LoadDumpDataCSV_V2 (line 53)
dataArray = textscan(fileID, formatSpec, 'Delimiter',
',', 'MultipleDelimsAsOne', false, 'ReturnOnError',
false);

4 Commenti

Stephen23
Stephen23 il 17 Giu 2016
Modificato: Stephen23 il 17 Giu 2016
@Tina Zhao: please edit your question and upload a sample file using the paperclip button. Then we have something to test our code on.
Is this a constant string or could it be anything, just non-numeric? And what kind of numerics, floating point with/without E, integer, what are the boundaries here?
I'm thinking you'll probably do better to read the file as a char() array and then process in memory unless it's simply too big...
If the file starts as binary, why not parse it as such rather than have an expensive binary to text conversion and an expensive parsing afterward?
Thanks for everyone's response. The file is pretty big, this is our internal tool data, up to a few hundred MB data.
I searched on others' post, and found this can solve my problem:
a2 = textscan(fileID, formatSpec, 'Delimiter', ',','HeaderLines',1,'CollectOutput',1);
% dataArray = textscan(fileID, '%f');
dataArray = [dataArray;a2{1}];
I think it skipped the whole row if there's a character, so my bad data can be much smaller.

Accedi per commentare.

Risposte (0)

Richiesto:

il 17 Giu 2016

Modificato:

il 17 Giu 2016

Community Treasure Hunt

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

Start Hunting!

Translated by