What I'm ideally trying to do is to have a variant subsystem change its variant based on the CLASS TYPE of a variable (that class provides all the parameters for the given variant).
Since I can't quite understand the rationale of the Variant system, especially the string conditions etc. and why there need to be Variant-Objects for each Variant of a Variant-Subsystem, this is what I'm currently trying to do:
Matlab script to run the model:
model = load_system('variant_test_model');
hws = get_param (model, 'modelworkspace');
myval = foo_class();
hws.assignin('obj', myval );
X = sim('variant_test_model', 'SolverType', 'Fixed-step', 'Solver', 'ode4', 'FixedStep', '1e-5', ...
'StartTime', '0', 'StopTime', '1', 'SaveOutput','on','OutputSaveName','outputs' );
Model's Init Function:
variant_variable = 1;
variant1 = Simulink.Variant('variant_variable == 1');
variant2 = Simulink.Variant('variant_variable == 2');
Model's Start Function:
if( strcmp( class( obj ), 'foo_class' ) == 1 )
variant_variable = 1;
elseif( strcmp( class( obj ), 'bar_class' ) == 1 )
variant_variable = 2;
end
I would have liked it to be more centered in the Variant-Subsystem instead of the model's properties, but the Variant-Design of Simulink seems not to be capable of that.
Now my problem is, I get the error message "Undefined function or variable 'obj'." during the StartFcn process. I can only assume that the sim command actually reloads the model and therefore uses a different workspace than the one I implanted "obj" into.
Now I would be grateful if somebody could help me get this working and even more if someone can come up with a cleaner design of what I'm trying to do.
Kind Regards, Michael
