MATLAB: How to get rid of the error: Error using horzcat. Dimensions of matrices being concatenated are not consistent.

dpcmhorzcatmatrices

I am trying to change my tutor's matlab code he gave us to suit my own for an assignment. This code is supposed to perform DPCM on an audio signal that I sampled, called "sampleData". This is the error:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in tryin_a_ting_PCM (line 111) diffpcm = [store, diffpcm];
Below is the relevant segment of my code: % Performing DPCM
SampledData = sampleData(:,1);
store = SampledData(1); diffpcm = SampledData(1:(length(SampledData))-1)-SampledData(2:length(SampledData)); diffpcm = [store, diffpcm];
recon = zeros(1,length(diffpcm)); recon(1) = diffpcm(1); for i = 2:length(recon) recon(i) = recon(i-1) – diffpcm(i); end
% note that 'sampleData' is my sampled audio signal.
In my MATLAB Workspace it says that the variable 'store' has the value '0', and the variable 'diffpcm' has the value '54289×1 double'.
Am I supposed to change the value of 'store' somehow to have a value of '54289×1' to work?

Best Answer

Try transposing 'diffpcm'
diffpcm = [store, diffpcm'];
If you want it back as a column vector afterwards then transpose again:
diffpcm = [store, diffpcm']';
54289x1 means 54289 rows and 1 column so you cannot concatenate with a scalar horizontally which has only 1 row. Transposing to a row vector allows you to do so though.