2
votes

I want to use scripting to create and define a variant subsystem in simulink.

I am able to create the variant subsystem and add subsystems within it using the add_block but cannot find the appropriate property that defines the variant subsystem by using the get_param command.

The way I graphically configure a variant subsystem is by right clicking the block and going to Block Parameters and then adding the variant control conditions for each subsystem.

I want to do the same thing but from an m-file so that I can create multiple blocks programmatically.

I checked the documentation and google search but couldn't find anything.

Thanks in advance.

2
I don't even want to know why you wish to do this programmatically, but you might be able to find the answer you're looking for by opening the model in a text editor and looking at the subsystem's properties. You should be able to get_param / set_param your way to the correct setting by trial and error.Praetorian
Opening the file in the text editor (btw, for .slx files you first have to extract it using a zip program and then open the xml file in an editor) I was able to see that the variant conditions are stored in the subsystems within the variant subsystem and not within the top-level variant subsystem. So you store the condition within each subsystem's "VariantControl" parameter. Example: set_param(sys,'VariantControl','a==1') where sys is a subsystem within the variant subsystem.ashah

2 Answers

1
votes

Based on a comment by @Praetorian, I opened the model in a text editor and found the parameter line where the variant condition was defined.

I found that the variant conditions are stored in the subsystems within the variant subsystem and not within the top-level variant subsystem.

So you store the condition within each subsystem's "VariantControl" parameter.

Example: set_param([variantSys '/' sys],'VariantControl','a==1') where sys is a subsystem within the variant subsystem variantSys.

0
votes

The variant control should be written on the Callbacks of the Model. In order to put the simulink variant controls available to the model, the variables should be created in the workspace. For this to happen you need to put your Sys = Simulink.Variant(Mode== value) etc on the PreLoadFcn.

Check access PreLoadFcn and put the formulas in there then your table will be automatically filled.

If you do not mind can you tell me how you created the variant subsystem?

Good luck