Not enough input arguments error in nlinfit
조회 수: 10 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
추가 답변 (2개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!