This page can perhaps help you:
http://www.efunda.com/math/leastsqua...sqrmdcurve.cfm
it's linked from
http://www.efunda.com/math/leastsqua...astsquares.cfm
These pages seem good, there's a linear example as well.
To do this in MATLAB, use the polyfit() function.