필터 지우기
필터 지우기

indepvar and depvar are of inconsistent sizes with polyfitn

조회 수: 11 (최근 30일)
mohamed gryaa
mohamed gryaa 2019년 9월 4일
댓글: mohamed gryaa 2019년 9월 4일
when i use polyfitn with matlab say indepvar and depvar are of inconsistent sizes and i don't now where i am wrong can yo help me?
this is the data:
x1=[2.2 2.2 2.2 2.44 2.49 2.48 2.45 2.2 2.39 2.38];
>> x2=[29.4 30.9 32.9 26.9 28 28.8 30.1 29.4 28.8 30];
>> y=[7.5 7.02 6.94 7.91 7.96 7.91 7.78 7.42 7.86 7.47];
p=polyfitn([x1,x2],y,1)
Error using polyfitn (line 172)
indepvar and depvar are of inconsistent sizes.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 9월 4일
Yes, you send in an array [x1,x2] of size [1 x 20] and an array y of size [ 1 x 10] into polyfitn. The polyfitn version I have (a matlab-central submission by John d'Errico from 2006) gives me a more sensible result after transposing your inputs:
p=polyfitn([x1;x2]',y',1)
p =
ModelTerms: [3x2 double]
Coefficients: [1.5589 -0.11979 7.4607]
ParameterVar: [0.1693 0.0010284 2.9687]
ParameterStd: [0.41146 0.032068 1.723]
R2: 0.91523
RMSE: 0.10284
VarNames: {}
This was my curse when starting to use matlab - I solved it by the very sofisticated technique:
If it doesn't work transpose, transpose again until all combinations have been tried.
You might do the same but a more intelligent aproach is to check the documentation and input variables.
HTH

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by