Error with GA: Conversion to double from struct is not possible.

2 views (last 30 days)
I’m trying to optimize stiffness of a spring in a train suspension system by GA. I get the value of fitness function from “To workspace” block, from a simulink model named “R1” which do a co-simulation by SIMPACK for getting the final result. As I run GA the following error occurs:
??? The following error occurred converting from struct to double:
Error using ==> double
Conversion to double from struct is not possible.
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score =
fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 291
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
28 rethrow(userFcn_ME)
I don’t know how can I eliminate this weird error? I’m pressed with time unfortunately. Here is my code:
function [R]=Ride(d1)
%Calling the Function to Update Variables
'SubvarUpd';
%Running GA for Simulink Block
options = simset('SrcWorkspace','current');
R1
sim('R1',[],options)
R=RideComfortindex
And “SubvarUpd” function is:
function SubvarUpd(d1)
kpx=d1;
fileID = fopen('F:\MST\Optimization\1\mysubvar.subvar','w'); %This is the address of SubVar file
% Longitudinal Stiffness subvar:
fprintf(fileID,'%s','subvar($_Rnom, str = ''');
fprintf(fileID,'%d',kpx);
  1 Comment
Geoff Hayes
Geoff Hayes on 30 Nov 2014
Katie - what is your fitness function because it isn't clear from the above code which (of the functions that you provided) it is. The error is telling you that there is a problem with it, so you may want to take a closer look at this function.

Sign in to comment.

Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!