Compute linear fit between vectors 'x' and 'y'


Updated 16 May 2017

View License


[Coeffs, Rho, R2, Residuals] = linfit(x,y)

Compute linear fit between vectors 'x' and 'y', and return the coefficients of the regression
line, the correlation between 'x' and 'y', the coefficient of determination ("how much knowing x it
is possible to determine y"), and the residuals. If the residuals exhibit "non-random" patterns, it
is an indication that a linear fit is not so good. To check them: bar(x,Residuals), xlabel('x'), ylabel('ŷ - y')
Note: the function ignores non-finite values(-Inf,Inf,NaN).

Cite As

Ruggero G. Bettinardi (2023). linfit(x,y) (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes