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 Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by