Error : "Too many input arguments"

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!

 Réponse acceptée

Star Strider
Star Strider le 3 Jan 2017
Modifié(e) : Star Strider le 3 Jan 2017

0 votes

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 commentaires

amine&&
amine&& le 3 Jan 2017
Modifié(e) : amine&& le 3 Jan 2017
Hello Star. I have already written this way. Thanks!
I rewrote the mseFunction under this form :
%%Déclaration de la fonction objective qu'on va utiliser
function MSE=mseFunction(alpha,beta,y,yS)
%%Calcul de la moyenne mobile d'ordre 48 pour les 6 jours
%Initialisation du vecteur qui va contenir la moyenne mobile
MMCS=zeros(240,1);
%Calcul de la moyenne mobile
for i=1:240
MMCS(i)=1/48.*((yS(i)/2)+sum(yS(i+1:i+47))+(yS(i+48)/2));
end
%Remplir les 24 premieres et derniéres cases par des zeros
MoyenneMobileCentreeS = padarray(MMCS,24,'both');
%%Calcul des composantes saisonniares
yMS=yS(25:264)./MoyenneMobileCentreeS(25:264);
%Réecrire le vecteur de telle sorte que les 24 premieres et derniére
%valeurs soient des zéros
bS = padarray(yMS,24,'both');
%Ecrire les valeurs du vecteur sous forme d'une matrice avec 48 lignes et 7 colonnes
MS = reshape(bS,[48,6]);
%Remplacer les zeros par des valeurs NaN pour ne pas les introduire dans le
%calcul de la médianne
MS(1:24,1)=NaN;
MS(25:48,6)=NaN;
%Calcul de la médianne de chaque ligne de la matrice
ComposantsSaisonniersS = nanmedian(MS,2);
%%Lissage exponnentiel simple
LES=zeros(288,1);
LES(25)=MoyenneMobileCentreeS(25);
for i=26:264;
LES(i)=alpha.*MoyenneMobileCentreeS(i)+(1-alpha).*LES(i-1);
end
%%Intégration de la composante saisonniére
S=zeros(264,1);
S(1:48,:)=ComposantsSaisonniersS;
for j=49:264;
S(j)=beta.*(yS(j)./LES(j))+(1-beta).*S(j-48);
end
%%Prévision
PREV=zeros(264,1);
PREV(26:264)=S(26:264).*LES(25:263);
PREV2=padarray(PREV(:),24,'post');
%%Calcul de la MSE
MSE = [mean((y(26:264)-PREV2(26:264)).^2),gradIent(alpha,beta,y,yS)'];
Star Strider
Star Strider le 3 Jan 2017
My pleasure!
Did my Answer solve your problem?
amine&&
amine&& le 3 Jan 2017
Hi. The problem is not solved.
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Niels
Niels le 3 Jan 2017
Modifié(e) : Niels le 3 Jan 2017

0 votes

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 commentaires

Star Strider
Star Strider le 3 Jan 2017
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.
Hello Niels. I get this error :
Error using mseFunction
Too many input arguments.
Error in @(x1,x2)mseFunction(x1,x2,y,yS)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by