Getting the equation of a line
273 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I used polyfit to create a trendline for a data set and that worked great. Now I am trying to get the equation of that trendline but I am a little stuck so any direction on that would be great. The code I used can be found here:
subplot (2,1,2)
time = (0:.00274:21.3644); %time in years to be able to plot the NAVD88 data
% Fit a polynomial p of degree 1 to the NAVD88 data. This will give a
% trendline and allow to solve a projection
x = (0:.00491814:21.3644);
y = Hclean;
p = polyfit(x,y,1);
% Evaluate the fitted polynomial p and plot:
projection = polyval(p,x);
plot(time,H,x,projection,'-')%Plot of all the waves over 21 years
title ('NAVD88 Low-High Daily Water Height for 21 year data set')
xlabel ('Years since Jan. 18 2000')
ylabel ('NAVD88 (ft)')
0 commentaires
Réponses (1)
John D'Errico
le 26 Mai 2021
Modifié(e) : John D'Errico
le 26 Mai 2021
You did the fit, with the estimates of the coefficients in p. p is a vector, of length 2.
The line equation is simple.
y = p(1)*x + p(2)
Had you just read the help for polyfit,
help polyfit
you would have learned exactly that.
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!