How to save regular audio files as variables with for loop?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SeokWon CHOI
el 23 de Mzo. de 2022
Comentada: SeokWon CHOI
el 2 de Oct. de 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?
Respuesta aceptada
Pooja Kumari
el 28 de Sept. de 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
Más respuestas (0)
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!