How to speed up saving data to .txt file?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I am working on large data - several hundered waveforems, each with sampling rate of 10e7. My goal is to save data in to the txt file. Currently I am using 'writematrix' and 'append' for including all the information I need. The part of my code looks as follow:
for i = 1:length(Signal)
writematrix('Sampling Rate [Hz]:',SaveFile,'WriteMode','append');
writematrix(SampRate,SaveFile,'WriteMode','append');
writematrix('Test Time [sec]:',SaveFile,'WriteMode','append');
writematrix(TestTime(i),SaveFile,'WriteMode','append');
writematrix('Amplitude [mV]:',SaveFile,'WriteMode','append');
writematrix(Signal{i},SaveFile,'Delimiter','space','WriteMode','append');
writematrix('',SaveFile,'WriteMode','append');
end
As for now, the procoess of saving the data take forever. Is there any way to speed it up?
0 comentarios
Respuesta aceptada
Jan
el 2 de Sept. de 2021
Editada: Jan
el 26 de Sept. de 2021
fopen, fprintf or even better fwrite is much faster than the very smart writematrix. Appending requires to open the file and searching the end. It is much faster to open the file once only and write the data directly.
fid = open(Savefile, 'W');
for i = 1:length(Signal)
fprintf(fid, 'Sampling Rate [Hz]: %d\n', SampRate);
fprintf(fid, 'Test Time [sec]: %g', TestTime(i));
fprintf(fid, 'Amplitude [mV]:\n');
fprintf(fid, '%g ', Signal{i});
fprintf(fid, '\n');
end
fclose(fid);
Más respuestas (0)
Ver también
Categorías
Más información sobre Java Package Integration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!