too many output argument

I am working on control of robot puma560 by using Matlab Simulink which contains 5 Matlab function blocks. when I run a genetic algorithm to tune PD, it says too many output argument. does ga conflict with Matlab function blocks in Simulink or what?
%fitness function
function y=fit2(x)
global kp kv
kp=x(1);
kv=x(2);
disp([kp kv])
sim('new_sim2qaex')
y= mean(abs(error));
Too many output arguments.
Error in fit2 (line 8)
y= mean(abs(error));
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in gamultiobjMakeState (line 27)
Score = FitnessFcn(state.Population(1,:));
Error in gamultiobjsolve (line 8)
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 274)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Caused by:
Failure in initial fitness function evaluation. GAMULTIOBJ cannot continue.

2 Comments

global variables act differently in Simulink. You should avoid using them.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 25 Mar 2019

0 votes

Assign a value to the variable error before calling sim
Otherwise, MATLAB will think you are referring to the function named error(), which does not have any outputs.

Asked:

on 25 Mar 2019

Commented:

on 25 Mar 2019

Community Treasure Hunt

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

Start Hunting!