How to code a basic fitting quadratic in this?

조회 수: 4 (최근 30일)
Wolfgang McCormack
Wolfgang McCormack 2021년 2월 2일
댓글: Walter Roberson 2021년 2월 3일
Hi everyone,
I am using two scatter plots. How can I code the quadratic fitting in that? I tried more than 7 ways on the internet and it's not working. It does not work with polyfit n=5. It just turns into a mesy multiple lines!
Thanks
s
ScatterPlotPreCOVID = scatter(x,y,'o')
hold on
ScatterPlotPostCOVID = scatter(x1,y1,'^')
hold off
Now, I do not insist coding it into it but I cannot have both quadratics simultanously for two datasets from the tools too.

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 2일
P = polyfit(x, y, 2);
The approximation function is then P(1)*x^2 + P(2)*x + P(3)
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 2월 3일
You already Accepted my answer, earlier ;-)
Walter Roberson
Walter Roberson 2021년 2월 3일
By the way, the way to do it without polyval would have been
P = polyfit(x, y, 2);
XI = linspace(min(x), max(x));
YI = P(1).*XI.^2 + P(2).*XI + P(3);
plot(XI, YI, 'k-');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by