fit data with a line

1 view (last 30 days)
Sarah Smith
Sarah Smith on 19 Jun 2020
Commented: darova on 19 Jun 2020
ok
  1 Comment
darova
darova on 19 Jun 2020
please don't remove your question

Sign in to comment.

Answers (1)

Ameer Hamza
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

Community Treasure Hunt

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

Start Hunting!