%% Create Variant Controls Using an In-Memory Enumeration Class
% Each variant choice in a Simulink(R) model is associated with a
% conditional expression called a _variant control_. The variant control 
% that evaluates to true determines the active variant choice in the model. This
% example shows how to create variant controls in your model using an
% in-memory enumeration class. The enumeration is created using the
% |<docid:simulink_ref#btyoygu Simulink.defineIntEnumType>| function. You
% do not need to save the enumeration in a MATLAB(R) file. In code
% generation, enumerated types improve readability because condition values
% are represented as meaningful names instead of literal values.

% Copyright 2020 The MathWorks, Inc.

%% Explore the Model
% Open the model |slexVariantSetupUsingInMemoryEnums|. It contains two variant
% choices, |Linear controller| and |Nonlinear controller|. Variant Sink and
% Variant Source blocks are used to implement the variant regions.
open_system('slexVariantSetupUsingInMemoryEnums');
%% Specify the Enumeration Class in the |PreLoad| Callback of the Model
% In this example, the enumeration class |Controller| is defined in the
% model |PreLoad| callback function. The enumeration class defines two
% enumeration members, |Linear| and |Nonlinear|, with underlying integer
% values |0| and |1|. The enumeration definition is exported to a header
% file named |Controller.h| during code generation. The MATLAB variable |V|
% is used as the variant control variable to store the currently active
% variant choice.
%%
Simulink.defineIntEnumType('Controller',...
    {'Linear', 'Nonlinear'}, [0;1], 'Description', 'Controller',...
    'DefaultValue', 'Linear', 'HeaderFile', 'Controller.h', 'DataScope',...
    'Exported');
V = Controller.Linear;
%% Build the Variant Condition Expression 
% You can set the variant controls from the Variant Manager. To open the
% Variant Manager, right-click the variant badge on the Variant Sink
% or Variant Source block and select *Open in Variant Manager* . 
%%
% You can see how the enumeration members and the control variable is used
% to create the condition expressions |V == ControllerChoice.Linear| and |V
% == ControllerChoice.Nonlinear|.  All supported Simulink enumerations
% can be used to build the condition expression. For information on
% enumerations in Simulink, see <docid:simulink_ug#bspsfem Simulink
% Enumerations>.
%%
% <<../variant_manager_inmemoryenum.png>>
%
%% See Also
% * <docid:simulink_ug#bt_5z2b-1 Introduction to Variant Controls>
% * <docid:simulink_ug#mw_b1911ab0-0a22-4665-a6a6-46d68abc7d3d Approaches for Specifying Variant Controls>
% * <docid:simulink_ug#brscdkf-1 Use Enumerated Data in Simulink Models>
% * <docid:simulink_ref#btyoygu Simulink.defineIntEnumType>