# Linear Fitting starting from a value

1 vue (au cours des 30 derniers jours)
Nicola De Noni le 10 Oct 2022
Modifié(e) : Torsten le 10 Oct 2022
Hi everyone!
I need to fit these data [100 90 80 70 50 45 40 43 42 40 35] whom are distanced by 10 seconds.
The problem is that I would fit these data starting from the first value (100) in order to understand the slope of the line.
Is it possible?
Thanks!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Torsten le 10 Oct 2022
Modifié(e) : Torsten le 10 Oct 2022
Sure. Use
l(x) = a*x + 100
as model function and fit the parameter a.
xdata = ...; % your xdata as column vector
ydata = ...; % your ydata as column vector
a = xdata\(ydata-100)
But starting from a certain x-value, the slope seems to change. You should separate the fit into two parts:
l1(x) = a*x + 100 0 <= x<= x1
l2(x) = b*x + [(a-b)*x1 + 100] x1 <= x <= x(end)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (1)

Hiro Yoshino le 10 Oct 2022
Modifié(e) : Hiro Yoshino le 10 Oct 2022
refline is the easiest way to achieve that.
y = [100 90 80 70 50 45 40 43 42 40 35];
x = 0:10:10*(length(y)-1);
plot(x,y,'o');
refline
if you want to know the coefficients:
p = polyfit(x,y,1)
p = 1×2
-0.6391 89.6818
polyfit for reference.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Nicola De Noni le 10 Oct 2022
Thanks @Hiro but i would like that the fitting line passe through the first point 100,0

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by