How to plot a 3rd order best fit line through 3 sets of data?

2 vues (au cours des 30 derniers jours)
CM
CM le 5 Avr 2016
I have 3 sets of data as vectors. X terms Cp80, Cp50, Cp30 and their corresponding Cv80, Cv50, and Cv30 y terms. I currently am using this block of code to plot them.
figure
hold on
plot(Cv80,Cp80,'*')
plot(Cv50,Cp50,'o')
plot(Cv30,Cp30,'p')
hold off
I need to run a third order best fit line through these three data sets and generate the R^2 value. I am unfamiliar with Polyfit, as I always use the basic fitting tools on the plot, and the documentation is less than helpful. I would appreciate it greatly if someone could show me how to fit one line and its R^2 value to these three datasets.

Réponses (2)

Roger Stafford
Roger Stafford le 5 Avr 2016
Modifié(e) : Roger Stafford le 5 Avr 2016
How about
x1 = [Cv80(:);Cv50(:);Cv30(:)];
y1 = [Cp80(:);Cp50(:);Cp30(:)];
p = polyfit(x1,y1,3);
y = polyval(p,x1);
plot(x1,y)
If the values of x1 are not monotone, you can first sort them:
x1 = [Cv80(:);Cv50(:);Cv30(:)];
y1 = [Cp80(:);Cp50(:);Cp30(:)];
[x1,ix] = sort(x1);
y1 = y1(ix);
p = polyfit(x1,y1,3);
y = polyval(p,x1);
plot(x1,y)

Muhammad Usman Saleem
Muhammad Usman Saleem le 5 Avr 2016
for R^2

Catégories

En savoir plus sur Descriptive Statistics 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!

Translated by