1

我试图绘制回归曲线:

coef_fit = polyfit(norm_dist,norm_time,7); 
y_fit = polyval(coef_fit,xlim); 
plot(xlim,y_fit,'r');

但它总是根据我通过的顺序绘制一条线。

4

1 回答 1

2

问题是x您使用的值是输出 ot xlim,它是一个长度为 2 的向量。您需要定义x具有更多值的向量:

norm_dist = sort(5*randn(1,50) + (1:50)); %// example x values
norm_time = 5*randn(1,50) + (1:50).^2; %// example y values
x = linspace(min(norm_dist), max(norm_dist), 200); %// define x values for plot
coef_fit = polyfit(norm_dist,norm_time,7); 
y_fit = polyval(coef_fit,x); 
plot(x,y_fit,'r');
hold on
plot(norm_dist, norm_time, 'b.') %// plot original points for comparison

在此处输入图像描述

于 2016-03-31T23:04:49.497 回答