MATLAB Answers

How to fit data to a curve with known error bars and draw it?

253 views (last 30 days)
tensorisation
tensorisation on 12 Aug 2019
Commented: Adam Danz on 17 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')

  7 Comments

Show 4 older comments
darova
darova on 17 Aug 2019
What about little trick? Just to parse boundaries of data
% x, y - rows data
x1 = [x; x+0.01];
x1 = x1(:);
y1 = [y-err; y+err];
y1 = y1(:);
f = fit(x1,y1);
img.png

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 17 Aug 2019
Edited: 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.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!