Get the first file in each folder
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Safwana Razak
el 25 de Nov. de 2019
Respondida: jibrahim
el 5 de Dic. de 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 comentarios
Respuesta aceptada
jibrahim
el 5 de Dic. de 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 comentarios
Más respuestas (1)
Constantino Carlos Reyes-Aldasoro
el 25 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!