How can I create a bus for Simulink from a Matlab function?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a function (myFunc) where I call a Simulink model that uses bus structures.
Before calling the model from myFunc, I used the following commands to create the bus and just run the model:
% References
busInfo2=Simulink.Bus.createObject(REF);
RefVectorBus = eval(busInfo2.busName);
clear slBus1; %(slBus1 is the default name. As I changed it to RefVectorBus, I can clear slBus1)
% Controller Configuration
busInfo3=Simulink.Bus.createObject(controllerConfig);
controllerConfigBus = eval(busInfo3.busName);
clear slBus1;
But now that I have this:
output = myFunc (input)
//declare model parameters (as I use current workspace)
//initialize bus:
% References
busInfo2=Simulink.Bus.createObject(REF);
RefVectorBus = eval(busInfo2.busName);
clear slBus1;
% Controller Configuration
busInfo3=Simulink.Bus.createObject(controllerConfig);
controllerConfigBus = eval(busInfo3.busName);
clear slBus1;
//call the model (USING CURRENT WORKSPACE)
SimulationOut = sim('myModel','SaveOutput','on', 'SrcWorkspace','current');
...
end (myFunc)
The problem is that Matlab doesn't allow me to create the bus ("Undefined function or variable 'slBus1'"). Is there a problem with the current workspace? Is matlab looking for the bus info in the base workspace?
I need the current workspace because the myFunc is a fitness function handle for a genetic algorithm and some of the Model parameters are beig estimated so I have to define them INSIDE myFunc and not in the base Workspace.
How can I solve this? Thanks to you
댓글 수: 0
답변 (1개)
Josep Virgili LLop
2017년 3월 29일
편집: Josep Virgili LLop
2017년 3월 29일
When using `Simulink.Bus.createObject` Matlab assigns the bus object to the base workspace and, as far as I know, this behavior can't be changed.
If you want to recover the Simulink bus in the current workspace use `evalin`
busInfo=Simulink.Bus.createObject(struct);
slBus = evalin('base',busInfo.busName);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!