Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Benjamin Colbert
Benjamin Colbert le 14 Sep 2019
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 commentaires
Benjamin Colbert
Benjamin Colbert le 15 Sep 2019
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 le 19 Sep 2019
If possible, can you give me the names of the files with which you have saved them in your folder?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by