How do I parse mixed, dynamic binary & string files?
I'm having trouble parsing files that are mixed strings & numbers. The data I need is in 3 columns (comma-delimited), and isn't in any specific form. It can have 10 leading gibberish characters, it might have some letters, symbols, numbers, it might say "Error: hrere" on 1 line (for example). I've used textscan, strread, !strings, fgetl with strread, but I can't seem to get what I need out into 3 variables [Col1 Col2 Col3]. Been racking my brain...How can I do this! Here's a sample of the file:
@#*%;AJ))&3#* a) 24.568, 34.1024, -0.1023
&$@!*(!( (*&Y$)@ 24.568, 34.1020, -0.0888
()(@E$@!*(!( (*&Y$)@ 23.568, 34.1020, -0.0888
$64&$@!*(!( (*&Y$)@ 24.4568, 34.0020, -0.0888
Bad Command
$64&$@!*(!( (*&Y$)@ 24.4568, 34.0020, -0.0888
$64&$@!*(!( (*&Y$)@ 24.4568, 34.0020, -0.0888
&!)*~*(ER!( (*6&Y$)@ 24.568, 34.1020, -0.0888
(*!$)^@ 23.568, 34.1020, -0.0888
etc....
The closest I got was using something like:
fid = fopen('file.txt','r'); tline = fgetl(fid); [c1 c2 c3] = strread(tline,'%f','delimiter',','); fclose(fid);
but I can't iterate it, and it quits also if I read a line with a bad string (non-floating point)
1 commentaire
Réponse acceptée
2 commentaires
Plus de réponses (0)
Voir également
Catégories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!