how can I select variant by script
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello Mathworks community ,
I'm trying to convert a model (slx) into executable (.exe), so i'm giving as inputs all the fixed parameters and tunnables.
my model includes varaiant subsystems , I would like to know if it is feasible with a script to choose the variant I want once I have the file executable (.EXE).
0 Commenti
Risposte (1)
Dinesh
il 3 Lug 2024
Hello.
Yes, this can be achieved if you make use of the "MATLAB Function" block. In the Simulink model where you have the "Variant Subsystem" block, add an "Inport" block and connect it to the "MATLAB Function" block. In the "MATLAB Function" block, you can do any of the following:
Choice 1:
If "Variant Subsystem" is in label mode (If the "Variant Control Mode" is set to "label"), then the input for this function can be the name of the variant choice block that should be chosen. For example, if you have 3 variant choice blocks with block names as "SS1", "SS2" and "SS3", then you can pass either of them as the input to the function. Within that function, you can make use of the "set_param" function and modify the "LabelModeActiveChoice" parameter to the input value passed. This would modify the variant choice of the block.
set_param(blockName,'LabelModeActiveChoice', variantChoiceBlockName)
"blockName" is the block name of "Variant Subsystem". "variantChoiceBlockName" is the block name of the variant choice that you want to select.
Here's the documentation link for the same: https://www.mathworks.com/help/simulink/ug/variant-control-modes-in-variant-blocks.html#mw_d07c2f29-fd8d-488c-8434-71e830b00199:~:text=set_param(blockName%2C%27LabelModeActiveChoice%27%2C%20%27variantChoiceLabel%27)
Choice 2:
If "Variant Subsystem" is in expression mode (If the "Variant Control Mode" is set to "expression"), then you need to set the "Variant Control Expression" for each of the variant choice. In this MATLAB function, according to the input specified, you can change the Variant Control Variable's value in such a way that the variant choice corresponding to the input of this function is chosen. For example, if the Variant control expression for "SS1" is "A==1", for "SS2" is "A==2", and for "SS3" is "A==3", then in the function, if the input is "SS3", then you can modify the value of "A" to 3 so that "SS3" is set as the variant choice. Make sure to initialize the variant control variable "A" to any value in the model's initialization function so that there are errors that occur when "A" is not initialized.
Here is the documentation link that will help you understand "expression" mode better: https://www.mathworks.com/help/simulink/ug/variant-control-modes-in-variant-blocks.html#mw_d07c2f29-fd8d-488c-8434-71e830b00199:~:text=expression%20in%20the-,Variant%20control%20expression,-parameter%20of%20the
Once you implement either of these, you could create an executable out of the Simulink model and pass the input argument while executing the ".exe" file. This input argument will be used by the "MATLAB Function" block to set the required variant choice for the "Variant Subsystem" block. If there are multiple "Variant Subsystem" blocks, then you also need to pass the block name as another parameter.
I hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Component-Based Modeling in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!