Get the first file in each folder

22 ビュー (過去 30 日間)
Safwana Razak
Safwana Razak 2019 年 11 月 25 日
回答済み: jibrahim 2019 年 12 月 5 日
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
Annotation 2019-11-25 172805.png

採用された回答

jibrahim
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.

その他の回答 (1 件)

Constantino Carlos Reyes-Aldasoro
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.

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by