필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Benjamin Colbert
Benjamin Colbert 2019년 9월 14일
댓글: Priyanshu Mishra 2019년 9월 19일
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에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by