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

8 vues (au cours des 30 derniers jours)
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 commentaires
decimad
decimad le 20 Fév 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 le 20 Fév 2016
Modifié(e) : decimad le 20 Fév 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 :-(

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Component-Based Modeling dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by