polyfit finds the coefficients of a polynomial that fits a set of data in a least-squares sense:
www.mathworks.com