MATLAB: How to concatenate two audio files of different matrix dimensions

audiodspmatrixvertcat

Hi all,
this is my code-
[y1,Fs] = audioread('M:\audio files\british.wav');
len= length(y1);
[y2,Fs] = audioread('M:\audio files\door1.wav');
q=44100; %sampling rate of y1
% Extract first 10second samples from y1,
% Then attach y2,
% Then extract the remaining samples
% and stick them on the end.
y3 = [y1(1:q*10,:); y2; y1(q*10+1:end)];
audiowrite('M:\audio files\british.wav', y3,Fs);
the error message which i get is-
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in Untitled2 (line 13)
y3 = [y1(1:q*10,:); y2; y1(q*10+1:end)];
can anyone please help me with this problem?

Best Answer

You're missing the column indexing in your y1(q*10+1:end), therefore it's converted into a row vector, which will have a different number of columns than y2 and y1(1:q*10,:). The correct code:
y3 = [y1(1:q*10,:); y2; y1(q*10+1:end, :)]; %that last colon is critical
Of course, y2 must have the same numbers of channels as y1 for the above to work.