- "X" is a design matrix of predictor (independent variable) values, with one row for each value in "Y", and one column for each predictor.
- "Y" for fitting the nonlinear regression function, specified as a vector with the same number of rows as "X".
- Nonlinear regression model function, specified as a function handle. "modelfun" must accept two input arguments, a coefficient vector and an array "X" respectively and return a vector of fitted response values.
nlinfit error too many input arguments in the model function
12 次查看(过去 30 天)
显示 更早的评论
I am trying to use the nlinfit and for the model, i definded a function for it. it keeps on showing error caused by Too many input arguments. I tried lowring the input arguments many time but it still did not work. in the code A, B, C and D, are all 4*4 matrices.
[th,R,J,COVB,mse] = nlinfit(U,Y,@(th,U)getlabel(th,U),th0,options);
function y = getlabel(th,pass)
global dsystem;
global Yall;
global TH;
dsystem.init = 0;
timestep = 120;
shift_val = 0.8;
th = 0.6;
U = pass.U;
PARANOM = pass.paranom;
nstates= pass.nstates;
ninputs= pass.ninputs;
ndata = pass.ndata;
xinter = pass.xinter;
paralist = cat(2,PARANOM.rvalues,PARANOM.cvalues);
TH = paralist.*(1 + sin(th)*shift_val);
sys = ss(A,B,C,D);
sysd = c2d(sys,timestep);
Ad = sysd.A; Bd = sysd.B;
Cd = sysd.C; Dd = sysd.D;
Yall=zeros(4,4);
for i = 1:ndata
xinter = (X(i,:)) * Ad + (U(i,:)) * Bd ;
Yall(i,:) = ((X(i,:)) * Cd ) + ((U(i,:)) * Dd );
end
y = Yall;
end
0 个评论
回答(1 个)
SAI SRUJAN
2023-10-31
Hi Hani Alkhatib,
I understand that you are facing an issue using the "nlinfit" MATLAB function.
The error "Too many input arguments" in the nlinfit function occurs when the number of input arguments provided to the model function is not consistent with the expected number of arguments.
You can follow the given example to proceed further.
modelfun = @(b,x)(b(1)+b(2)*exp(-b(3)*x));
rng('default') % for reproducibility
b = [1;3;2];
x = exprnd(2,100,1);
y = modelfun(b,x) + normrnd(0,0.1,100,1);
beta0 = [2;2;2];
beta = nlinfit(x,y,modelfun,beta0)
% The correct nlinfit format for getLabel
% [th,R,J,COVB,mse] = nlinfit(U,Y,@getlabel,th0,options);
The function "nlinfit" has specific conditions that need to be met by the input parameters.
For a comprehensive understanding of the "nlinfit" function in MATLAB, please refer to the provided documentation below,
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!