fit data with a line
Show older comments
Answers (1)
Ameer Hamza
on 19 Jun 2020
Try something like this
x = linspace(0, 1, 100);
y = 3*x + 2 + rand(size(x));
pf = polyfit(x, y, 1);
y_pred = polyval(pf, x);
r2 = rsquare(y, y_pred); % R-squared
sse = sum((y-y_pred).^2); % SSE
2 Comments
Sarah Smith
on 19 Jun 2020
Ameer Hamza
on 19 Jun 2020
Oh! I forgot to mention, rsquare is from this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/34492-r-square-the-coefficient-of-determination
Categories
Find more on Get Started with Curve Fitting Toolbox 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!