function [b0, b1]=Line1(X) %function [b0, b1]=Line1(x,y) % Returns the "best fitting" line for y=b0x+b1 %Example of use. The vectors x and y may be either rows or columns. %x=[1 2 3]; y=[2 1 0]; % [b0, b1]=Line1(x,y); % t=linspace(min(x),max(x)); % yhat=b0*t+b1; x=X(:,1); y=X(:,2); %x=x(:); y=y(:); %Makes x, y into columns A=[x ones(size(x))]; b=A\y; b0=b(1); b1=b(2);