Cannot use sim command in genetic algorithm

2 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2017-7-20
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 个评论
Walter Roberson
Walter Roberson 2017-7-20
What techniques are you using to fetch parameters from a workspace?
Imisi Jo
Imisi Jo 2017-7-25
Figured it out! Like you said, I had to ensure the workspace I was using was the current workspace so I used simset('SrcWorkspace','Current'). Thanks for your suggestion!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by