フィルターのクリア

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 Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by