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')

답변 (2개)

Elad
Elad 2013년 8월 19일

0 개 추천

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));
Bahloul Derradji
Bahloul Derradji 2018년 12월 8일

0 개 추천

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!

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

Jac
2013년 8월 19일

답변:

2018년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by