To load multiple audio files into an array in MATLAB, you can use the audioread
function in a loop to read each file and append it to a cell array. Here is an example code that reads all the files in a folder and stores them in a cell array:
main.m364 chars12 lines
In this example, folder_path
is the path to the folder containing the audio files, files
is a list of all the files in the folder that match the specified format, and num_files
is the total number of files.
Inside the loop, audioread
is used to read the audio data and sampling rate from each file, which is then stored in a cell array audio_data
.
Note that audioread
returns the audio data as a matrix, where each column represents a channel in the audio file (e.g. left and right). You can extract a specific channel by indexing the matrix like this: audio_data{i}(:, 1)
for the first channel.
Also, if the audio files have different lengths or sampling rates, you may need to pad or resample them to ensure they can be stored in the same array.
gistlibby LogSnag