# Please help to solve: Index in position 1 exceeds array bounds. Index must not exceed 1.

1 view (last 30 days)
Rizwan on 7 Apr 2023
Answered: 埃博拉酱 on 7 Apr 2023
% Define drum sounds
% Load the drum sounds into a cell array
drum_sounds = {open_hihat, closed_hihat, snare_drum, bass_drum, tom_toms, cymbals};
% Define the bpm and the number of beats in the song
fs=44100;
bpm = 130;
num_beats = 457;
% Calculate the period between two beats in seconds
period = 130 / bpm;
% Load the drum table from Table 1
drum_table = [0 1 1 1 0 0 0 1 1;
0 0 0 1 0 1 1 0 1;
0 1 0 1 1 0 0 1 1;
1 1 1 1 1 0 0 0 1;
0 0 0 1 0 1 1 0 1;
0 0 0 1 0 1 1 0 1;];
% Initialize the audio signal
audio_signal = zeros(1, num_beats * fs * period);
% Loop through each beat in the song and add the corresponding drum sounds
for i = 1:num_beats
for j = 1:6
if drum_table(j,i) == 1
start_index = round((i-1) * fs * period) + 1;
end_index = start_index + size(drum_sounds{j}) - 1;
audio_signal(start_index:end_index,:) = audio_signal(start_index:end_index,:) + drum_sounds{j};
end
end
end
% Normalize the audio signal
audio_signal = audio_signal / max(abs(audio_signal));
% Write the audio signal to a wave file
audiowrite('assign_drum_beats.wav', audio_signal, fs);
KALYAN ACHARJYA on 7 Apr 2023
Provide those audio data, so that we can try?
Rizwan on 7 Apr 2023
Pleases find the attached audio files

Your audio_signal is an 1×n row vector but you're trying to get its start_index:end_index rows.