Create a fit for data with a polynom first degree
Show older comments
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

Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
