File Exchange

image thumbnail

Linear fit with both uncertainties in x and in y

version (12 KB) by Julien Browaeys
Performs a linear fit with uncertainties in x and y, using a Monte Carlo method


Updated 25 Oct 2017

View License

This tool computes a linear fit when there are uncertainties in x data and y data. The best slope and intercept are computed by minimizing the chi2 calculated using both standard deviation on x and y (Deming fit). Data points are simulated using a Monte Carlo method so as to obtain the error on the fitted parameters.
If error on both x and y is not specified, error is assumed constant on y and computed.
Result of the fit is by default displayed, the best fit and a hull of all the possible fits are drawn.

Cite As

Julien Browaeys (2019). Linear fit with both uncertainties in x and in y (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Great code!
Just one question: which is the level of the confidence lines plotted in the figure? 95%? or 90%?

Kevin Chen

Great code!!
One small thingy: when you do not plot, a figure still appears. I changed that by putting the holdstatus (line 100) to:

if plotting

and it works.


Correction of an old bug. Now if 'plotting' is set to false, the correct comportement is obtained: no plot is displayed.

Added reference to Matlab central in the help.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux