From: John D'Errico on
"Giorgio " <christianjp(a)inwind.it> wrote in message <htpdoh$s1$1(a)fred.mathworks.com>...

> i am new to matlab, but my attempt appears to work
>
> function [intercept,slope]=linfix(x,y,xcord,ycord)
>
> % estimates OLS regression for bidemsional data set
>
> xi=x-xcord;
> yi=y-ycord;
>
> slope=sum((xi).*(yi))/sum((xi).^2);
> intercept=ycord-slope*xcord;
>
> t=linspace(min(x),max(x),100);
> plot(x,y,'x',t,t.*slope+intercept,'-');
>
> of course, comments welcome

While you may be new to matlab, you are also new
to understanding how to solve numerical problems.

I suggested the use of backslash for a REASON.
Your solution squares numbers for no good reason.
This can cause numerical problems.

As I said in my first response, use the simple and
direct

slope = (x - x0)\(y-y0);

John