Main Content

setState

Configure block states for code generation

    Description

    example

    setState(myCodeMappingObj,block,Name,Value) configures specified block states for code generation. Use this function to map specified block states to the storage class and storage class property settings that the code generator uses to produce C code for the states.

    Examples

    collapse all

    In the model code mappings for model myConfigModel, set the storage class for the state X of Unit Delay block Delay to ExportedGlobal.

    cm = coder.mapping.api.get('myConfigModel');
    setState(cm,'myConfigModel/Delay','StorageClass','ExportedGlobal');
    

    In the model code mappings for model myConfigModel, configure the storage class for block states throughout the model to Model default.

    cm = coder.mapping.api.get('myConfigModel');
    blockHandles = find(cm,'States')
    setState(cm,blockHandles,'StorageClass','Model default');
    

    In the model code mappings for model myConfigModel, configure the code identifier for the state X of Unit Delay block Delay to dstate_X.

    cm = coder.mapping.api.get('myConfigModel');
    setState(cm,blockHandle,'Identifier','dstate_X');
    

    Input Arguments

    collapse all

    Code mapping object (model code mappings) returned by a call to function coder.mapping.api.get.

    Example: myCM

    Path or handle of the block containing the state to configure. To specify multiple block states, use a cell array.

    Example: blockHandle

    Data Types: char | string | block_handle | cell

    Name-Value Pair Arguments

    Example: 'StorageClass' 'ExportedGlobal'

    Specify comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments as Name1,Value1,…,NameN,ValueN. The order of the name and value pair arguments does not matter.

    Storage class to set for the specified block state. The name of a predefined storage class or storage class that is defined in the Embedded Coder Dictionary associated with the model. See Configure Block States for C Code Generation.

    Name for the variable that represents the block state in the generated code.

    Data Types: char | string

    File name for a C source file that contains definitions for global data read by data elements and external code. Applies to storage classes ExportToFile and Volatile.

    Data Types: char | string

    Name of a get function that a data element calls in the generated code. Applies to storage class GetSet.

    Data Types: char | string

    File name for a C header file that contains declarations for global data read by data elements and external code. Applies to storage classes ExportToFile, GetSet, ImportFromFile, and Volatile.

    Data Types: char | string

    Name of the model that owns global data used by other models in the same model hierarchy. The code generated for the model that owns the data includes the global data definition. Applies to storage classes ExportToFile and Volatile.

    Data Types: char | string

    When model configuration parameter Array layout is set to Row-major, a flag that indicates whether to preserve dimensions of a data element represented in generated code as a multidimensional array. Applies to storage classes ExportToFile, ImportFromFile, Localizable, and Volatile.

    Data Types: logical

    Name of a set function that a data element calls in the generated code. Applies to storage class GetSet.

    Data Types: char | string

    Name that the code generator uses to identify the structure for a data element in the generated code. Applies to storage classes Bitfield and Struct.

    Data Types: char | string

    Storage class property defined in the Embedded Coder Dictionary. Values that you can specify vary depending on the storage class definition.

    Introduced in R2020b