MATLAB: Unable to perform assignment because the left and right sides have a different number of elements.

ecg

I am calculating first and second derivative for getting threshold values for ecg. but getting error. Please help.
for n=5:numel(ecgBR)
ecg_dif(n)=abs(ecgBR(n,1)-ecgBR(n-2,1));
ecg_dif2(n,1)=abs(ecgBR(n,1)-2*ecgBR(n-2,1)+ecgBR(n-4,1));
end
ERROR:Unable to perform assignment because the left and right sides have a different number of elements.
ecgBR=1X3600 double matrix

Best Answer

Since ecgBR has only one row, not n, you cannot do ecgBR(n, 1), which is the nth row in column 1. But you have 3600 columns, not 1, and 1 row, not 3600. Get rid of the ,1:
for n=5:numel(ecgBR)
ecg_dif(n)=abs(ecgBR(n)-ecgBR(n-2));
ecg_dif2(n)=abs(ecgBR(n)-2*ecgBR(n-2)+ecgBR(n-4));
end