fit data with a line
3 views (last 30 days)
Show older comments
ok
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
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
See Also
Categories
Find more on Least Squares 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!