필터 지우기
필터 지우기

Linear Regression not working

조회 수: 2 (최근 30일)
Grace Rembold
Grace Rembold 2019년 11월 25일
답변: Reshma Nerella 2020년 3월 13일
I'm trying to plot the same data multiple times but with a different degree of curve each time. Every time I try, the code runs through fine, but my plot does not show any line fit at all, it just shows my data points.
here is my current code.
X =
NaN
0.2200
0.3000
0.4400
0.4900
0.7000
0.8000
0.9000
1.1000
1.0000
1.1500
1.2000
1.2200
1.2600
1.2500
1.2700
1.2000
1.2200
1.2600
1.2000
1.2200
1.2600
1.2000
1.2200
1.2600
1.2500
t =
NaN
0
4
7
10
13
16
22
25
30
33
36
40
48
51
55
60
80
100
120
140
160
180
200
220
240
x=(t);
y6=(X);
% First Degree
subplot(1,3,1);
p=polyfit(x,y6,1);
f=polyval(p,x);
plot(x,y6,'o',x,f,'r-')
legend('data','linear fit')
% Second Degree
subplot(1,3,2);
p=polyfit(x,y6,2)
f=polyval(p,x)
plot(x,y6,'o',x,f,'r-')
% Third Degree
subplot(1,3,3);
p=polyfit(x,y6,3)
f=polyval(p,x)
plot(x,y6,'o',x,f,'r')

답변 (1개)

Reshma Nerella
Reshma Nerella 2020년 3월 13일
In the plot command,
plot(x,y6,'o',x,f,'r-')
you didn’t specify any line style, so you are getting only the data points
You may use the following to display the line
plot(x,y6,'-o',x,f,'r-') % specify line style along with marker.
Refer the following link for documentation of plot

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by