Simulink loading- and simulation-procedure from Matlab script considering variant subsystems.

조회 수: 2 (최근 30일)
Hi there,
I'm currently wondering about when Simulink models Variant-Systems are evaluated when calling "load_system" to load a model inside a script.
My current approach is
function result = some_method( self )
h = load_system('foo');
hws = get_param (model, 'modelworkspace');
hws.assignin('sim_config', self);
result = sim('foo', ...);
end
Now I've got multiple problems with that.
- How does the "sim" command actually know the "h" model handle and use that instance, since I only pass the model name? - Is it not too late to define the workspace variables afer the load_system call, especially considering variant subsystems? - Is "load_system + sim" the intended pattern for what I'm doing?
Kind Regards, Michael
  댓글 수: 5
decimad
decimad 2016년 2월 20일
My next attempt, which seems to get me halfway to intended behaviour is
if( strcmp( class( cfg ), 'foo_class' ) == 1 )
set_param(gcb, 'OverrideUsingVariant', 'foo == 1');
elseif( strcmp( class( cfg ), 'bar_class' ) == 1 )
set_param(gcb, 'OverrideUsingVariant', 'foo == 2');
end
inside the Mask Initializer. However, if the model is not opened, but merely opened by "sim", the mask initializer seems to run too late, yielding the error message
"Block 'variant_test_model/Variant Subsystem' attempted to change the active variant during simulation. The active
variant must be configured before the simulation is started."
Even the Block's StartFcn-callback comes to late for this call. Any suggestions?
decimad
decimad 2016년 2월 20일
편집: decimad 2016년 2월 20일
Even more experiments led to
set_param('variant_test_model/Variant Subsystem', 'OverrideUsingVariant', 'foo == 1');
with which I can reliably change the Variant in use from my matlab script/function. Unfortunately, I was not able to find a model- (or preferrably block-) callback that gets called for each sim-call early enough to change the variant inside the model :-(

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Component-Based Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by