I am trying to use the fitnlm function and I keep getting this set of errors
In nlinfit>LMfit (line 579)
In nlinfit (line 276)
In NonLinearModel/fitter (line 1123)
In classreg.regr.FitObject/doFit (line 94)
In NonLinearModel.fit (line 1430)
In fitnlm (line 94)
Warning: Rank deficient, rank = 6, tol = 2.853427e-11.
Error using nlinfit>checkFunVals (line 641)
The function you provided as the MODELFUN input has returned Inf or NaN values.
Error in nlinfit>LMfit (line 588)
if funValCheck && ~isfinite(sse), checkFunVals(r); end
Error in nlinfit (line 276)
[beta,J,~,cause,fullr] = LMfit(X,yw, modelw,beta,options,verbose,maxiter);
Error in NonLinearModel/fitter (line 1123)
nlinfit(X,y,F,b0,opts,wtargs{:},errormodelargs{:});
Error in classreg.regr.FitObject/doFit (line 94)
model = fitter(model);
Error in NonLinearModel.fit (line 1430)
model = doFit(model);
Error in fitnlm (line 94)
model = NonLinearModel.fit(X,varargin{:});
Here is how I am calling the function (n13 is a single y variable, n_x is a 212x4 matrix of x variables, I have tried both versions of "modelfun" and neither works)
%modelfun = @(b,n_x)b(1) + b(2)*n_x(:,1).^b(3) + b(4)*n_x(:,2).^b(5) + b(6)*n_x(:,3).^b(7) + b(8)*n_x(:,4).^b(9);
modelfun = 'n13~b0+b1*x1^b2+b3*x2^b4+b5*x3^b6+b7*x4^b8';
beta0=ones(9,1);
NLM_n = fitnlm(n_x,n13,modelfun,beta0);
Not sure what the problem is. Any help would be great!

Réponses (1)

oyun kwon
oyun kwon le 9 Mar 2023

0 votes

Could you try adding '.' between parameter connetion part?
such as
your code
modelfun = 'n13~b0+b1*x1^b2+b3*x2^b4+b5*x3^b6+b7*x4^b8';
suggested code
modelfun = 'n13~b0+b1.*x1.^b2+b3.*x2.^b4+b5.*x3.^b6+b7.*x4.^b8';

Produits

Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by