Create a fit for data with a polynom first degree
이전 댓글 표시
Hey, I have two data sets that I have already plotted and now I want to create a new plot with a polynom first degree to have a linear model for my data and calculate the sum of squares from it. The problem is that in the new plot my data points are already linear even though they aren't and it shows me, that the sum of squares is 1, so I guess I made a mistake implenting the correct data.
x = [0.1201 0.1348 0.1708 0.4551 0.7091 1.5297 2.4558 4.4908 7.7372]; %Dataset 1
y = [0.5291 0.6967 1.1081 4.3538 7.2549 16.6232 27.1949 50.4295 87.4983]; %Dataset 2
plot(x,y,'o') %Plot dataset 1 and 2
p=polyfit(x,y,1); %Polynom first degree
py=polyval(p,x);
hold on
plot(x,py) %Insert the model in the plot
hold off
Rsq=1-sum((y-py).^2)/sum((y-mean(y)).^2);
Rsq=1.0000

채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

