Get the first file in each folder
조회 수: 10 (최근 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!