This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create a Simple Variant Model

  1. Create a model that contains variant blocks. For example, see Variant Subsystems that contains a Variant Subsystem block (Controller).

  2. Define variant control variables that determine the condition under which a variant choice is active.

    1. Right-click the variant block and click Block Parameters. The Block Parameters dialog box for the variant block opens.

    2. To choose the active Variant based on the evaluation of the Variant conditions, use the Expression mode else select Label mode. When you select the Variant control mode as Label, the Label mode active choice option is available. In Label mode, Variant control need not be created in the global workspace. You can select an active Variant choice from Label mode active choice options.

    3. Use the options available on the Block Parameter dialog box to add variant controls and its corresponding variant condition.

      A sample screenshot for Expression mode:

      A sample screenshot for Label mode:

      Note

      The variables used to specify the variant control and variant condition must be defined in the global workspace or data dictionary for the model.

  3. Specify a default variant condition to be used when there is no active variant choice. Use the Variant control dropdown menu to specify the default.

  4. To activate a variant choice, type the variant choice in MATLAB® command window. For example, type VSS_MODE = 2.

  5. To simulate the model, click Simulation > Run. The model simulates for the specified active choice.

  6. Modify the active choice and simulate the model again, if necessary.

  7. Generate code for the variants model with preprocessor conditionals.

    Note

    You must have an Embedded Coder® license to generate code.

    1. In the Block Parameters dialog box, select the Analyze all choices during update diagram and generate preprocessor conditionals check box.

    2. Open the Subsystem Block Parameters dialog boxes. Select the Treat as atomic unit parameter.

    3. In the Code Generation section of Configuration Parameters dialog box, specify the System target file as ert.tlc.

    4. In Model Explorer, define the variables used to specify the variant choice as a MATLAB variable or as a Simulink.Parameter. The data type of the Simulink.Parameter can be of type Integer, Boolean, or Enumerated and the storage class can be either importedDefine(Custom), Define(Custom), or CompilerFlag.

  8. For the variants that are defined in the global workspace, export the control variables to a MAT-file. For example, type the following in the MATLAB command window:

    1. save <MAT-File Name> <Variable Name>

    2. PostLoadCallback > load <MAT-File Name>

Note

To update or refresh active models that contain Variant Subsystem blocks, click Diagram > Refresh Blocks (Ctrl + K) or Simulink > Update Diagram (Ctrl + D) in Simulink®.

Related Topics