필터 지우기
필터 지우기

Error : "Too many input arguments"

조회 수: 2 (최근 30일)
amine&&
amine&& 2017년 1월 3일
댓글: Star Strider 2017년 1월 3일
Hello, wi type this code in matlab :
f = @(x)mseFunction(x(1),x(2),y,yS);
H=feval(f,xc(1),xc(2));
I get the following error :
Error using @(x)mseFunction(x(1),x(2),y,yS)
Too many input arguments.
Error in projbfgs (line 65)
H=feval(f,xc(1),xc(2));
I do not know where i made the mistake. Thanks!

채택된 답변

Star Strider
Star Strider 2017년 1월 3일
편집: Star Strider 2017년 1월 3일
If I remember correctly from your earlier Question, ‘mseFunction’ only has three arguments. If you want to pass it ‘y’ as well, you have to re-write the function definition to include it:
function MSE = mseFunction(alpha,beta,y,yS)
...REST OF YOUR CODE ...
end
EDIT Please do not use feval here. Just call your function as:
H = f(x);
assuming that ‘y’ and ‘yS’ are already in your workspace.
  댓글 수: 4
amine&&
amine&& 2017년 1월 3일
Hi. The problem is not solved.
Star Strider
Star Strider 2017년 1월 3일
I created a version of your function for testing purposes in my function testing ‘.m’ file.
When I ran the following code with it, it ran without error:
function MSE=mseFunction(alpha,beta,y,yS)
MSE = [alpha beta; y yS];
end
xc = [100; 102];
y = 20;
yS = 50;
f = @(x)mseFunction(x(1),x(2),y,yS);
H = f(xc)
H =
100 102
20 50
I cannot reproduce the problem you are getting.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Niels
Niels 2017년 1월 3일
편집: Niels 2017년 1월 3일
Hi,
yes, your defined f as a function with only 1 inputargument
f = @(x)mseFunction(x(1),x(2),y,yS);
but then you want it to have 2:
H=feval(f,-->xc(1),xc(2)<--);
so your x has to be a vector with length 2...
try
H=feval(f,xc);
or set f to
f = @(x1,x2)mseFunction(x1,x2,y,yS);
and
H=feval(f,xc(1),xc(2));
  댓글 수: 2
Star Strider
Star Strider 2017년 1월 3일
That won’t work here (see the previous Question Calculate the optimum of a function). The ‘mseFunction’ is an objective function for an optimisation routine, and takes a vector of parameters as an argument.
amine&&
amine&& 2017년 1월 3일
Hello Niels. I get this error :
Error using mseFunction
Too many input arguments.
Error in @(x1,x2)mseFunction(x1,x2,y,yS)

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by