Not enough input arguments
8 ビュー (過去 30 日間)
古いコメントを表示
All input variables are provided for in the code below, but still running it gives the "Not enough input arguments" error message. Can anyone help out?
PS: the function is doing nonlinear least squares of a weighted average of variables (x(2) and x(3))
function F = myfun2(x,n,cn);
F = @(x,n,cn)x(1)+n.*log(1+(1-exp(-cn))*x(2)+exp(-cn)*x(3));
FW=inline(char(F));
x=[0 0 0]
n=1:7
cn=0.5
ct=1
Fut=[5 4.9 4.8 4.65 4.5 4.3 4.05]
[x,resnorm] = lsqcurvefit(myfun2,x,n'-1-ct/12,Fut')
0 件のコメント
回答 (2 件)
Elad
2013 年 8 月 19 日
Hey, From matlab help it seems that
lsqcurvefit is a function of ( fun , x , xdata , ydata ) where fun is a function of ( x , xdata )
your myFun2 is a function of 3 input arguments .. not 2
another quick tip you might use, you dont have to create myFun2 as a function, you can write as a function handle
cn = 0.5; myFun2 = @(x,n)x(1)+n.*log(1+(1-exp(-cn))*x(2)+exp(-cn)*x(3));
0 件のコメント
Bahloul Derradji
2018 年 12 月 8 日
Try this code. It works.
the user defined function in a separate file named : myfun.m
function F = myfun(x,xdata,c)
F = x(1)*exp(c*xdata)+x(2)
end
the main script:
xdata = [3; 1; 4]; % example xdata
ydata = 6*exp(-1.5*xdata)+3; % example ydata
c = -1.5; % define parameter
x = lsqcurvefit(@(x,xdata) myfun(x,xdata,c),[5;1],xdata,ydata)
Good luck!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear Least Squares についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!