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

3 ビュー (過去 30 日間)
CM
CM 2016 年 4 月 5 日
編集済み: Roger Stafford 2016 年 4 月 5 日
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.

回答 (2 件)

Roger Stafford
Roger Stafford 2016 年 4 月 5 日
編集済み: Roger Stafford 2016 年 4 月 5 日
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 2016 年 4 月 5 日
for R^2

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by