Not enough input arguments error in nlinfit
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Awanthika Senarath
le 31 Mai 2018
Commenté : Star Strider
le 31 Mai 2018
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 commentaires
Réponse acceptée
Star Strider
le 31 Mai 2018
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 commentaires
Plus de réponses (2)
Darren Wethington
le 31 Mai 2018
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 commentaires
Voir également
Catégories
En savoir plus sur Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!