Not enough input arguments error in nlinfit

조회 수: 10 (최근 30일)
Awanthika Senarath
Awanthika Senarath 2018년 5월 31일
댓글: Star Strider 2018년 5월 31일
Hello all,
I'm quite new to matlab and I'm trying to fit a non linear model to my data (I have 3 independent variables, 4000+ data points)
I have written the following code after following few you tube videos and matlab documents. Result is a 4000*4 matrix that has my three independent variables and the dependent variable
x=Result.x;% independent variable I
y=Result.y;% independent variable II
z=Result.z;% independent variable III
p=Result.fx; % dependent variable
inputs=[x,y,z];
my_fun = @(beta,x,y,z) (x.^beta(1) * y.^beta(2) / z.^beta(3)); % assumed model
initials = [1,2,1];
new_coeff = nlinfit(inputs,p,my_fun,initials);
However, I get the following error when I run this code
Error using nlinfit (line 205)
Error evaluating model function '@(beta,x,y,z)(x.^beta(1)*y.^beta(2)/z.^beta(3))'.
Error in Untitled5 (line 11)
new_coeff = nlinfit(inputs,p,my_fun,initials);
Caused by:
Not enough input arguments.
Can someone help me? Why does it say not enough input parameters?

채택된 답변

Star Strider
Star Strider 2018년 5월 31일
Try this:
inputs = [x(:),y(:),z(:)];
my_fun = @(beta,inputs) (inputs(:,1).^beta(1) .* inputs(:,2).^beta(2) ./ inputs(:,3).^beta(3)); % assumed model
That should work with this nlinfit call:
new_coeff = nlinfit(inputs,p,my_fun,initials
(I cannot test your code.)
  댓글 수: 2
Awanthika Senarath
Awanthika Senarath 2018년 5월 31일
편집: Awanthika Senarath 2018년 5월 31일
Thanks, this was the error. I had passed too many arguments. Matlab seriously needs to re-do their error messages!
Star Strider
Star Strider 2018년 5월 31일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Darren Wethington
Darren Wethington 2018년 5월 31일
When passing arguments to nlinfit, you've (correctly) passed your inputs as one variable, "inputs". Now my_fun will take "initials" as the argument "beta", "inputs" as the argument "x", and... no input argument for "y" or "z".
Try changing my_fun to take two arguments, "beta" and "data" for instance. Then specify in my_fun that x=data(1,:), y=data(2,:), etc (or whatever makes sense for your data). Hopefully this helps.

Awanthika Senarath
Awanthika Senarath 2018년 5월 31일
I solved it, the model_fun only takes two parameters. I changed it as follows and now it works.
my_fun = @(beta,Results) (Result.x.^beta(1) .* Result.y.^beta(2) ./ Result.z.^beta(3));

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by