how do i sequentially audioread and sequentially name audio data as variables in matlab

You can use a for loop to sequentially read and name audio data as variables in Matlab. Here's some sample code:

main.m
for i = 1:num_files % num_file is the total number of audio files you want to process
    filename = sprintf('audio_%d.wav', i); % create filename for each audio file using a counter
    [audio, fs] = audioread(filename); % read the audio file
    variable_name = sprintf('audio%d', i); % create a unique variable name for the audio data
    eval(sprintf('%s = audio;', variable_name)); % assign the audio data as a variable using the unique variable name
end
460 chars
7 lines

In this code, we use sprintf to create a unique filename and a unique variable name for the audio data, based on the loop counter. We then use audioread to read the audio file and eval to create a variable with the unique variable name and assign the audio data to it.

Note: eval can be potentially dangerous, so use it with caution.

related categories

gistlibby LogSnag