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

8 visualizzazioni (ultimi 30 giorni)
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 Commenti
decimad
decimad il 20 Feb 2016
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 il 20 Feb 2016
Modificato: decimad il 20 Feb 2016
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 :-(

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Component-Based Modeling in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by