Filter löschen
Filter löschen

how can I select variant by script

4 Ansichten (letzte 30 Tage)
Glorio_sebastien
Glorio_sebastien am 11 Jun. 2019
Beantwortet: Dinesh am 3 Jul. 2024 um 6:27
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).

Antworten (1)

Dinesh
Dinesh am 3 Jul. 2024 um 6:27
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.
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.
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!

Kategorien

Mehr zu Component-Based Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by