How can I write self-invoking code for hundreds of wav files for the same loop and call those files to matlab?

1 vue (au cours des 30 derniers jours)
How can I write self-invoking code for hundreds of wav files for the same loop and call those files to matlab?I have hundreds of wav files, how can I name them in the loop that I will call them?
  3 commentaires
Jan
Jan le 22 Nov 2022
"how can I name them in the loop" - if you mention, how the names should look like, suggesting some code is much easier. What does "self-invoking code" means?

Connectez-vous pour commenter.

Réponses (1)

Mathieu NOE
Mathieu NOE le 22 Nov 2022
hello
something like this ?
this demoes the excellent FEX submission
dir is not 100% sure for natural sorting
in the for loop we show how you can use the created structure S to store new information / code results
expand as you wish
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'*.wav')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
filename = S(k).name % to actually show filenames are sorted (see command window)
[signal,Fs] = audioread( fullfile(fileDir, filename));
% code example below
% save signal data inside structure S
S(k).Fs = Fs;
S(k).signal = signal;
end

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by