How to save regular audio files as variables with for loop?
4 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
Pooja Kumari
2023-9-28
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!