help with regression fitting - curvilinear

조회 수: 2 (최근 30일)
Eric Escoto
Eric Escoto 2021년 10월 4일
댓글: Eric Escoto 2021년 10월 4일
I lost on why the model cant plot a single line after fitting a regression to the data (example data attached).
I'm using,
p = polyfit(data(:,2), data:,1), 2);
ypoly = poly val(p, data(:,2));
figure
plot(data(:,2), data(:,1), 'o')
hold on
plot(data(:,2), ypoly)
The figure looks like this (attached) with lines all over instead of one smooth curve.

채택된 답변

KSSV
KSSV 2021년 10월 4일
편집: KSSV 2021년 10월 4일
load('data.mat')
p = polyfit(data(:,2), data(:,1), 2);
xi = linspace(min(data(:,1)),max(data(:,2)),1000) ;
yi = polyval(p, xi);
figure
plot(data(:,2), data(:,1), 'o')
hold on
plot(xi,yi)
You made some syntax errors in the given code. Check with the given code.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by