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

2 ビュー (過去 30 日間)
decimad
decimad 2016 年 2 月 20 日
編集済み: decimad 2016 年 2 月 20 日
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 Center および File ExchangeComponent-Based Modeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by