How to save regular audio files as variables with for loop?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
SeokWon CHOI
il 23 Mar 2022
Commentato: SeokWon CHOI
il 2 Ott 2023
I want to save regular audio files as aa1.wav, aa2.wav ... aai.wav in a variable via audioread syntax.
For example,
load handel.mat
for i=1:2
Y{i} = audioread('aa1.wav');
end
How can I do?
Risposta accettata
Pooja Kumari
il 28 Set 2023
Dear SeokWon,
It is my understanding that you are facing issues with saving regular audio files such as “aa1.wav”, “aa2.wav”, “aa3.wav”, …., “aa1.wav” as variables using “for” loop via “audioread” syntax.
There is an error in your code in “for” loop in which you have specified “aa1.wav” file, every time the loops run it will store file1, you can read different audio files such as “aa1.wav”, “aa2.wav”…”aai.wav” using “sprintf” function in MATLAB. You can refer to the below documentation for more information on “sprintf” function:
Below is the code for your reference:
% Load handel.mat if it is not already in your workspace
load handel.mat
% Define the number of audio files you want to read
numFiles = 3;
% Create a cell array to store the audio data
Y = cell(numFiles, 1);
% Loop through the desired number of files
for i = 1:numFiles
% Construct the file name using the desired format
fileName = sprintf('aa%d.wav', i);
% Read the audio file using audioread and store it in the cell array
Y{i} = audioread(fileName);
end
I hope this helps!
Regards,
Pooja Kumari
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Audio and Video Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!