Linear Regression not working
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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')
0 件のコメント
回答 (1 件)
  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 
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!