1、使用 polyfit 函数估计多项式模型的系数,然后使用 polyval 函数根据预测变量的任意撕良滤儆值评估模型。以下代码使用 6 次多项式模型拟合第三个十字路口的流量数据:load count.dat
2、c3 = count(:,3); % Data at intersection 3
3、tdata = (1:24)';
4、p_coeffs = polyfit(tdata,c3,6);
5、figure
6、plot(c3,'o-')
7、hold on
8、tfit = (1:0.01:24)';
9、yfit = polyval(p_coeffs,tfit);
10、plot(tfit,yfit,'r-','LineWidth',2)
11、legend('Data','Polynomial Fit','Location','NW')