Get the first file in each folder
11 次查看(过去 30 天)
显示 更早的评论
hi,
i have a main folder named audio, 10 subfolder inside there. how do i loop and read 1st file in each folder. i just able to read 10th first file in my audiodatastore. i want to display each categories (of my subfolder) in my plot. figure below is my code and output of one of my subfolder label, it should be different label for each plot.
datafolder = mypath;
ads = audioDatastore(datafolder, ...
'IncludeSubfolders',true, ...
'FileExtensions','.wav', ...
'LabelSource','foldernames')
idx = 1:10;
for i = 1:10
[x,fs] = audioread(ads.Files{idx(i)});
subplot(2,5,i)
plot(x)
axis tight
title(string(ads.Labels(idx(i))))
sound(x,fs)
pause(2)
end
0 个评论
采纳的回答
jibrahim
2019-12-5
Hi Safwana,
If you are only interested in one file from each subfolder, then you can do this:
ads_small = splitEachLabel(ads,1)
That new datastore should have one file per subfolder.
0 个评论
更多回答(1 个)
Constantino Carlos Reyes-Aldasoro
2019-11-25
Use the command "dir" and do it in loops:
dir0 = dir('firstFolder');
numEntries = size(dir0,1)
Then loop:
for k=1:numEntries
if isdir(dir0(k).name)
% This is a sub-folder read again
dir1=dir(strcat('firstFolder',filesep,dir0(k).name));
% you could loop again over this folder
else
% This is not a folder
end
end
by the way, your display of the title is interpreting as latex or something else and that is why the c is low, use
'interpreter','none'
with title to avoid this.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!