Code for saving files as .mat is very very slow

5 次查看(过去 30 天)
Hi,
I am loading multiple .csv files into matlab and re-saving them as .mat files. The code takes way too long (hours) to save each file as a .mat file. Code is below:
myfiles = dir('*.txt') ;
p = length(myfiles) ;
for i = 1:p
thisfile = myfiles(i).name ;
y = importdata(thisfile) ;
matfile = strcat(thisfile,'.mat')
save(matfile,'y') ;
clearvars y
end
Any hint or help?
Thank you
  10 个评论
dpb
dpb 2020-6-30
"it takes a few seconds to save each file as .mat file. If the number of csv files increases to say 1000, its takes much much longer"
Yes, overall time, but have you profiled to prove it's actually the save operation that's the culprit?
Which OS? Olden FAT32 days large numbers of files in a subdirectory would really bog things down; NTFS is better in that regard but I don't know whether the problem really goes away--or is mostly just not observed by not running things that emphasize the problems that might be.
I wonder if there's any chance it could have anything to do with acessing/releasing system resources like file handles, etc..so one ends up with the slowness owing to waits inside the system calls in the i/o routines?
All just conjecture...

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by