Error while running ga code. How to use function handler .? Undefined function or variable 'FcnArgs'

I have error while running my M file.
My function handler is as follows
h=@(x) rmse_test(x,FcnArgs{net:inputs:target});
But i'm getting error like this
Undefined function or variable 'FcnArgs'.
Error in genetic_algorithm (line 25)
h = @(x) rmse_test(x,FcnArgs{net:inputs:targets});
createAnonymousFcn is inbuilt function like this
function fcn_handle = createAnonymousFcn(fcn,FcnArgs)
%CREATEFUNCTIONHANDLE create an anonymous function handle
%
% fcn: A function handle
% args: A cell array of extra arguments to user's objective/constraint
% function
% Copyright 2011 The MathWorks, Inc.
% $Revision: 1.1.6.1 $Date: 2011/10/27 00:34:50 $
fcn_handle = @(x) fcn(x,FcnArgs{:});
Could anyone help me to solve this error..??

Risposte (1)

Your function handler should not be that. Your function handler should be the result of calling
createAnonymousFcn( @rmse_test, {net, inputs, target})

3 Commenti

Now i changed my function handler like this
h = @(x) rmse_test(x,{net:inputs:targets});
after changing i'm getting error like this
Undefined function 'colon' for input arguments of type 'network'.
Error in @(x)rmse_test(x,{net:inputs:targets})
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 14) y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 47) Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 41) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 351) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in genetic_algorithm (line 55) [x_ga_opt, err_ga] = ga(h, 3, ga_opts); Caused by: Failure in user-supplied fitness function evaluation. GA cannot continue.
how can i solve this error.could you please help me..??
h = createAnonymousFcn( @rmse_test, {net, inputs, target});
@Walter Roberson
When i change my function handler as mentioned above i'm getting error like this
Index exceeds matrix dimensions.
Error in setwb (line 32) net.IW{i,j}(:) = x(inputWeightInd{i,j});
Error in rmse_test (line 17) net = setwb(net, x');
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 14) y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 47) Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 41) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 351) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in genetic_algorithm (line 55) [x_ga_opt, err_ga] = ga(h, 3, ga_opts); Caused by: Failure in user-supplied fitness function evaluation. GA cannot continue.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by