Getting "Index exceeds the number of array elements" error and not sure why

1 次查看(过去 30 天)
I am writing a script to automatically sort files by a character string in the file name (i.e. sort by date). I am getting the following error:
"Index exceeds the number of array elements (1).
Error in sort_files (line 16)
movefile(fullfile(filelist(i).folder, filelist(i).name), [DiroUT,filesep,int2str(str2num(name(7:8)))]) "
I am just learning MATLAB and could use some advice.
DirIn = 'C:\Users\colbe\OneDrive\Documents\Backup\PhD Project Stuff\Soundscape Project\Experiment' %set incoming directory
DirOut = 'C:\Users\colbe\OneDrive\Documents\Backup\PhD Project Stuff\Soundscape Project\Experiment'
eval(['filelist=dir(''' DirIn '/*.wav'')']) %get file list
for i = 1:length(filelist);
Filename = filelist(i).name
name = strsplit(Filename, '_');
newStr = extractBetween(name,7,8);
if strcmp(newStr,'01')
movefile(fullfile(filelist(i).folder, filelist(i).name), [DirOut,filesep,int2str(str2num(name(7:8)))])
end
end
  3 个评论
Benjamin Colbert
Benjamin Colbert 2019-9-15
I think I have code to create the folders though I'm open to suggestions. And no, no reason to do 1 vs 01. You make a good point which I will implement. What I have is a folder of 4400 wav files (actually 2-4 folders every 2 months) and I want to auto sort them by date recorded (the 8-9 digits).
Priyanshu Mishra
Priyanshu Mishra 2019-9-19
If possible, can you give me the names of the files with which you have saved them in your folder?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by