How can I write self-invoking code for hundreds of wav files for the same loop and call those files to matlab?
1 view (last 30 days)
Show older comments
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 Comments
Jan
on 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?
Answers (1)
Mathieu NOE
on 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
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!