# error message using polyfit (nonlinear regression)

4 ビュー (過去 30 日間)
Locks 2013 年 4 月 20 日
hi,
I get the following error meesage:
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 71
In run at 74
The code I am using is the following:
for putCall =1:2
dataPutCall = data16(data16(:,3)==putCall,:);
dates=unique(dataPutCall(:,6));
for i=1:length(dates)
date=dates(i);
for indexT = 1:length(Ts)
T = Ts(indexT);
number=dataT(:,13);
x= dataT(:,2);
y=dataT(:,10);
p = polyfit(x,y,2);
f = polyval(p,x);
a=p(3);
b=p(2);
c=p(1);
SlopeSkew(number)=b+2*c.*x;
Slope=SlopeSkew';
end
end
end
I have used this code for a smaller matrix and there is was worked perfectly but not it seems as something is not working correctly and I am unsure what excatly it is

サインインしてコメントする。

### 採用された回答

bym 2013 年 4 月 20 日
I think it is obvious from the message; you don't have a enough data points to fit the polynomial uniquely. Like fitting a line through just one point, there are many solutions
x=[1,2];
y = [2,8];
polyfit(x,y,2)
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 72
##### 3 件のコメント表示 2 件の古いコメント非表示 2 件の古いコメント
Locks 2013 年 4 月 21 日
perfect, thanks

サインインしてコメントする。

### カテゴリ

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!