how can I appropriately get a for loop to extract wav files to sub folders(directories)??
2 次查看(过去 30 天)
显示 更早的评论
My currrent issue is trying to take a folder with 40 .wav files, (10s clips for each instrument that add up to 40s total)
but all are labeled, "01_composer_basson", "01_composer_violin"......"02_composer_basson"....and so on
I cannot seem to write a for loop properly to get all the 10s clips for each .wav into each of their own directories.
I can then break them up and anaylize them by cattinizing them.
How can i fix my loop so i can get each instrument .wav file to the directory?
i have this so far, i apologize in advanced for my lack of matlab skills!
%extracts the audio files from the main folder and puts them into folders
%based on their name.....
function [] = AudioExtract()
File = ls('\\users\audio_stems\');
%folders for seperate instruments
mkdir Basson
mkdir Saxphone
mkdir Clarinet
mkdir Violin
% the original folder all the files are in has 40 .wav files
%10 for each instrumnet
for i=1:42
% first reaults are a . then a ..(
if(File(i,3) ~= '_')
continue
else
if mod(i,3)==0
disp('.');
end
if (strfind(File(1,:), 'basson') ~= 0)
Intsrument = 'Basson';
else
(strfind(File(1,:), 'clarinet') ~=0);
Intrsrument = 'Carinet';
if (strfind(File(1,:), 'saxaphone') ~= 0)
Instrument='Saxaphone';
0 个评论
采纳的回答
Jan
2020-11-30
List = dir('\\users\audio_stems\*.wav');
%folders for seperate instruments
mkdir Basson
mkdir Saxphone
mkdir Clarinet
mkdir Violin
for k = 1:numel(List)
Name = List(k).name;
if contains(Name, 'bassson')
Intsrument = 'Basson';
elseif contains(Name, 'clarinet')
Intsrument = 'Basson';
... etc
end
movefile(Name, fullfile(Instrument, Name));
end
6 个评论
Turbulence Analysis
2020-12-1
Thanks, Jan.
I have opned a new thread.. Below is the link..
https://www.mathworks.com/matlabcentral/answers/670713-read-files-from-folder-and-subfolder
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!