Improve speed reading in a .dat file
Ältere Kommentare anzeigen
Im attempting to process some rather heafty .dat files with 500k+ lines. The bulk of my code runtime is being taken up by two functions
fgetl and str2double
Does anyone know a faster way to read in a dat file or functions that run faster
2 Kommentare
Stephen23
am 4 Mär. 2021
If at all possible, the fastest would be
but whether you can use it depends on the file format, which you have not told us anything about.
If you want further help with this, upload a representative** file by clicking the paperclip button.
** This means exactly the same file format, EOL characters, delimiter, number formats, etc., but small enough so that you can upload it on this forum. Probably you achieve this by keeping only the first few hundred lines.
Aaron Crawford
am 4 Mär. 2021
Antworten (2)
Image Analyst
am 4 Mär. 2021
0 Stimmen
You could try fileread() to read in the whole file into one variable in one shot, then go through it parsing it.
Some version of this is probably the fastest you can get:
[fid,msg] = fopen('example.txt','rt');
assert(fid>=3,msg)
for k = 1:5 % 5 header lines to ignore
fgetl(fid);
end
vec = fscanf(fid,'%f'); % fast!
fclose(fid);
fprintf('%.17f\n',vec)
Kategorien
Mehr zu Adding custom doc finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!