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

1 visualización (últimos 30 días)
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 comentarios
Benjamin Colbert
Benjamin Colbert el 15 de Sept. de 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 el 19 de Sept. de 2019
If possible, can you give me the names of the files with which you have saved them in your folder?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by