Asked by tensorisation
on 12 Aug 2019

Using built-in functions like fit(...) or nlinfit(...), how exactly do I fit data to a curve with known error bars?

Let's say in general I have

[x,y,err_x,err_y]

And now I want to make a fit for it, say: fit=fit(x,y,'exp1')

And later want to draw everything with the errorbars using errorbar(...)

How exactly do I do that?

EDIT: knowing how to do this for the more simple case of no errors in the X axis would also help. Say I have:

[x,y,err_y]

And now I want to make a fit for it, say: fit=fit(x,y,'exp1')

Answer by the cyclist
on 17 Aug 2019

Edited by the cyclist
on 17 Aug 2019

Do you mean that you want to do a fit where both your x and y variables have known measurement error? (Unlike, say, an ordinary least squares fit, where all error is assumed to be in y?)

To my knowledge, MATLAB does not have a built-in function for that. I have done Deming regression using this function from the File Exchange.

tensorisation
on 17 Aug 2019

Knowing how to do this for the case of only errors in y would also help me.

Let's say I have:

[x,y,err_y]

And now I want to make a fit for it, say: fit=fit(x,y,'exp1')

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## darova (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_734380

## tensorisation (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_734829

## darova (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_734896

## tensorisation (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_736105

## darova (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_736110

## darova (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_736111

## tensorisation (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/475882-how-to-fit-data-to-a-curve-with-known-error-bars-and-draw-it#comment_736138

Sign in to comment.