Test EOF while reading a file using csvread function
Afficher commentaires plus anciens
I am currently reading a .csv file in matlab using csvread function, and I am specifying where to begin and end reading. I would like to know if I am able to test if the current ending position extends beyond the end of file. Thank you. Andrei
Réponses (2)
Titus Edelhofer
le 2 Mai 2011
Hi Andrei,
not directly. There are several possibilities though: if you edit csvread, you see the call to dlmread. If you edit dlmread, you see somewhere around line 149 (depending on MATLAB version) a call to close the file:
fclose(fid);
So one option would be to copy both files to your local folder, rename them to e.g. mycsvread and mydlmread and before closing the file add something like
atTheEnd = feof(fid);
Or you could get the number of lines by
fid = fopen(filename, 'rt');
t = textscan(fid, '%s', 'delimiter', '\n');
nRows = length(t{1});
fclose(fid);
and compare nRows with you row parameter to csvread.
Titus
Andrei
le 2 Mai 2011
0 votes
Catégories
En savoir plus sur Data Import from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!