For files with some repeating numerical pattern like file0001, file0002...file0100, I've written the following script to operate on the input files and save the results with the same name.
% The folder has 100 files to be operated on
% "save_filename" is the name of data saved for the "inname" file
for k = 1:100
inputfiledir = './Data/Category1/';
if (k<10)
save_filename = sprintf('score_sp1_a000%d',k);
inname = sprintf('sp1_a000%d',k);
elseif (k>=10)
save_filename = sprintf('score_sp1_a00%d',k);
inname = sprintf('sp1_a00%d',k);
end
if (k>=100)
save_filename = sprintf('score_sp1_a0%d',k);
inname = sprintf('sp1_a0%d',k);
end
[prediction,score] = predict_class(trainedNet,strcat(inputfiledir,inname,'.wav'));
save(strcat('./VGGish/Data_PredScores/Categoty1/',save_filename),"prediction","score")
end
How do I do it for files with no pattern? I tried to use the ls command:
filename = ls()
But it returns the entire list of file names as a string, without separation.