function [A,B]=lsline(X,Y) %Call [A, B] = lsline(X,Y) % Fits the least squares line to data points % Input - X stores the x coordinates of the data points % - Y stores the y coordinates of the data points % Output - A and B in the least squares line y = Ax +B for the data points xmean=mean(X); ymean=mean(Y); sumx2=(X-xmean)*(X-xmean)'; sumxy=(Y-ymean)*(X-xmean)'; A=sumxy/sumx2; B=ymean-A*xmean;