How to improve read performance for a lot of large files

1 次查看(过去 30 天)

Hello everyone,

I have roughly 5,000 csv-files of the format 1,000,000x7 that contain seven time series. Amongst other things, I want to perform fft on those to create features for a neural network.

To use the data stored in the files I need to load them into the memory of course. As I will do this at different locations in my code a few times, I'd like to reduce the amount of code needed to read these files and the amount of time it takes to do so.

Using the normal csvread takes a lot of time per file and I always need to use the file's name which gives more code.

oldfolder = cd(datafolder);
filename  = 'filename.csv'; % There are many
signal = csvread(filename); % This takes ~4.3sec
cd(oldfolder)

I tried to load these files into a datastore (ds) which doesnt take long. I thought from here I could read the files more easily (which is true as I dont need to use the files' names anymore). The process of reading takes about the same time as before though (but still less code to write so preferred option up to here). If I then read the file from the ds I get a table as the first row of the csv-file is a string. To change that I need to get rid of the first line and then use table2array and str2double etc, as all data in the table is a string at that point. This takes a lot of time.

temp = table2array(read(ds)); % This takes ~3.4sec
signal = str2double(temp(2:end,2));  % This takes quite some time >30 sec

Do you have ideas how to improve the performance of reading timewise and codewise?

  1 个评论
Juri Maibaum
Juri Maibaum 2018-4-24
Best way I found was to read all csv-files one by one, process them to frequency spectry and save these as mat-files. This was done over the weekend for 40 hours. Now I load these mat-files whenever I need them. To load them it doesn't take a lot of time per file anymore.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by