Cannot use sim command in genetic algorithm
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Imisi Jo
am 20 Jul. 2017
Kommentiert: Imisi Jo
am 25 Jul. 2017
For some reason I cannot seem to run the sim command to simulate a model which is required to estimate parameters in the model which the genetic algorithm will do. I pass the objective function to ga:
%%load measured data
load('data_R01_full','simVol_TECM','simTime_TECM','simSoC_TECM','simOCV_TECM');
cap=0;
R0=47e-3;
%%set bounds
lb=[0;47e-3]; %cap, R0
ub=[0.2;75e-3];
%%est fcn
estfcn=@(x) gafunc(x,simVol_TECM,simOCV_TECM,simSoC_TECM,simTime_TECM);
%%estimation
[xOpt,fVal] = ga(estfcn,2,[],[],[],[],lb,ub);A
And my objective function starts with this:
function G = gafunc(x,Vbat_meas,OCV_meas,SoC_meas,t_meas)
open('gatest_ss_standalone');
run 'ga_standalone_tests';%loads all the variables necessary for simulation
cap_val=x(1);
R0=x(2);
[tout,~,output]=sim('gatest_ss_standalone',StopTime);
close('gatest_ss_standalone')
It never simulates because I get an error saying some parameters are undefined in the model, even though I have specified it in the script 'ga_standalone_tests'. Anyone know why I get this error?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Jul. 2017
Possibly your model is expecting to get the parameters from the base workspace. Some of the ways of fetching parameters can be configured specifically to look in the base workspace instead of in the current workspace.
Some of the blocks such as From Workspace normally look in the workspace of the function that calls sim() if the model is called by sim(), but look in the base workspace if the model is called by clicking on the model Run button or from the Simulink menus.
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!