how can I select variant by script

1 回表示 (過去 30 日間)
Glorio_sebastien
Glorio_sebastien 2019 年 6 月 11 日
回答済み: Dinesh 2024 年 7 月 3 日
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).

回答 (1 件)

Dinesh
Dinesh 2024 年 7 月 3 日
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!

カテゴリ

Help Center および File ExchangeSubsystems についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by