Hey @N/A, I assume that each time you compare 3 concecutive numbers from 'ritme' and based on the pattern it matches play that particular sound you can achieve this by making minor changes in your code as suggested below:
% Iterate over the rhythm pattern
for i = 1:(loop - 2)
% Extract a segment of the rhythm pattern
segment = ritme(i:i+2);
% Check which sound to play based on the pattern
if isequal(segment, bass)
% Play the kick sound
soundsc(kick, Fs);
elseif isequal(segment, hihat)
% Play the hi-hat sound
soundsc(hat, Fs);
elseif isequal(segment, snare)
% Play the snare sound
soundsc(snare, Fs);
end
% Pause for a short duration
pause(0.3);
end