Get the first file in each folder
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Safwana Razak
am 25 Nov. 2019
Beantwortet: jibrahim
am 5 Dez. 2019
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 Kommentare
Akzeptierte Antwort
jibrahim
am 5 Dez. 2019
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 Kommentare
Weitere Antworten (1)
Constantino Carlos Reyes-Aldasoro
am 25 Nov. 2019
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 Kommentare
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!