keep fscanf past wrong format value
Ältere Kommentare anzeigen
Hello, im having this problem with feof function and fscanf. I want to read all the whole numbers but it stops when it reaches something that is not. How can I make it ignore that and keep scanning?
fid = fopen("testdata.txt","r");
a = [];
i = 0;
while ~feof(fid)
i = i + 1;
a(i) = fscanf(fid, '%d', 1);
end
fclose(fid);
1 Kommentar
Rik
am 15 Mai 2023
Wouldn't you be better off reading the entire file and then matching each line with a regular expression?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Low-Level File I/O finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!