Documentation

Simulink.AliasType

Create alias for signal and parameter data type

Description

This class allows you to designate MATLAB® variables as aliases for signal and parameter data types. You designate variables as aliases by creating instances of this class and assigning them to variables in the MATLAB base workspace or a data dictionary (see Creating a Data Type Alias). The MATLAB variable to which a Simulink.AliasType object is assigned is called a data type alias. The data type to which an alias refers is called its base type. Simulink® software allows you to set the BaseType property of the object that the variable references, thereby designating the data type for which it is an alias.

Simulink software lets you use aliases instead of actual type names in dialog boxes and set_param commands to specify the data types of Simulink block outputs and parameters. Using aliases to specify signal and parameter data types can greatly simplify global changes to the signal and parameter data types that a model specifies. In particular, changing the data type of all signals and parameters whose data type is specified by an alias requires changing only the base type of the alias. By contrast, changing the data types of signals and parameters whose data types are specified by an actual type name requires respecifying the data type of each signal and parameter individually.

You can use objects of this class to create an alias for Simulink built-in data types, enumerated data types, Simulink.NumericType objects, and other Simulink.AliasType objects.

To define and name your own fixed-point data type, use an object of the class Simulink.NumericType. Objects of the class Simulink.AliasType can create an alias for a Simulink.NumericType object that defines a fixed-point data type, but cannot define a fixed-point data type.

Creating a Data Type Alias

You can use either the Model Explorer or MATLAB commands to create a data type alias. See MATLAB Commands for Creating Data Type Aliases.

To use the Model Explorer to create an alias:

  1. On the Model Explorer Model Hierarchy pane, select Base Workspace.

    You must create data type aliases in the MATLAB workspace or in a data dictionary. If you attempt to create an alias in a model workspace, Simulink software displays an error.

  2. From the Model Explorer Add menu, select Simulink.AliasType.

    Simulink software creates an instance of a Simulink.AliasType object and assigns it to a variable named Alias in the MATLAB workspace.

  3. Rename the variable to a more appropriate name, for example, a name that reflects its intended usage.

    To change the name, edit the name displayed in the Name field on the Model Explorer Contents pane.

  4. On the Model Explorer Dialog pane, in the Base type field, enter the name of the data type that this alias represents.

    You can specify the name of any existing standard or user-defined data type in this field. Skip this step if the base type is double (the default).

  5. Use the MATLAB save command to save the newly created alias in a MAT-file that can be loaded by the models in which it is used.

MATLAB Commands for Creating Data Type Aliases

Use the following syntax to create a data type alias at the command prompt or in a MATLAB script.

ALIAS = Simulink.AliasType;

ALIAS is the name of the variable that you want to serve as the alias. For example, the following line creates an alias named MyFloat.

MyFloat = Simulink.AliasType;

The following notations get and set the properties of a data type alias, respectively:

PROPVALUE = ALIAS.PROPNAME;
ALIAS.PROPNAME = PROPVALUE;

ALIAS is the name of the alias object, PROPNAME is the name of the alias object properties, and PROPVALUE is the property value. For example, the following code saves the current value of MyFloat's BaseType property and assigns it a new value.

old = MyFloat.BaseType;
MyFloat.BaseType = 'single';

For information on the names, permitted values, and usage of the properties of data type alias objects, see Properties.

Create Alias for Enumerated Data Type

You can use a Simulink.AliasType object to create an alias for an enumerated data type. For example, you can create an alias for an enumerated type called SlDemoSign.

myEnumAlias = Simulink.AliasType;
myEnumAlias.BaseType = 'Enum: SlDemoSign';

You can use the expression myEnumAlias to specify the data type of signals or parameters as the enumerated type SlDemoSign.

Data Type Aliases in Generated Code

If you have a Simulink Coder™ license, you can cause data type aliases to appear in the code generated for a model using any of the following methods:

  • Specifying the signal data type of a block in the model as a Simulink.AliasType via the Block Parameters dialog box.

  • Creating a Simulink.Signal object that uses the Simulink.AliasType as its data type. Use this signal object as the name of a signal in the model and specify that the signal name must resolve to an object in the MATLAB workspace. See Signal Objects for Code Generation in the Simulink Coder User's Guide.

  • Creating a Simulink.Parameter object that uses the Simulink.AliasType as its data type. Use this parameter object as a block parameter in the model. See Generated Code for Parameter Data Types in the Simulink Coder User's Guide.

    Notes  

    • If you assign a data type in a block dialog box and if you use a Simulink.Signal object on the signal feeding into the block, the code is always generated using the data type in the dialog box.

    • The Simulink Coder code generator tries to preserve the names of alias types in the generated code. However, in some cases, an alias type name can revert to its underlying equivalent built-in data type. If you have a Embedded Coder® license, you can specify that the code generator use the alias type name in the generated code, by using replacement types (see Data Type Replacement in the Embedded Coder documentation).

    • The Simulink.AliasType class does not support multiword data types for code generation.

    • You can specify the data type of a complex signal using the Simulink.AliasType class. In this case, if the DataScope property of the Simulink.AliasType class is set to Imported (or Auto with a header file specified), provide a definition for the complex type. As shown in the following example, the alias type definition, IAT_int32, must contain the name of the complex type prefixed by c.

      #ifndef myAliasTypes_H_
      #define myAliasTypes_H_
      
      #include "rtwtypes.h"
      
      typedef int32_T IAT_int32;
      typedef cint32_T cIAT_int32;
      
      #endif 

      In the preceding example, while you must define IAT_int32 in the base workspace, you do not need to define cIAT_int32 in the base workspace.

    • If you define two nested alias types, Simulink Coder generates an error if the DataScope property of the alias type is set to Imported or if either of the alias types specifies a header file.

Parent

None

Children

None

Property Dialog Box

Base type

The data type to which this alias refers. The default is double. To specify another data type, select the data type from the adjacent drop–down list of standard data types or enter the data type name in the edit field. You can, with one exception, specify a nonstandard data type, e.g., a data type defined by a Simulink.NumericType object, by entering the data type name in the edit field. The exception is a Simulink.NumericType whose Category is Fixed-point: unspecified scaling.

    Note:   Fixed-point: unspecified scaling is a partially specified type whose definition is completed by the block that uses the Simulink.NumericType. Forbidding its use in alias types avoids creating aliases that have different base types depending on where they are used.

Data scope

Specifies whether the data type definition is imported from, or exported to, a header file during code generation. The possible values are:

ValueAction
Auto (default)If no value is specified for Header file, export the type definition to model_types.h, where model is the model name. If you have an Embedded Coder license, and you have specified a data type replacement, then export the type definition to rtwtypes.h.

If a value is specified for Header file, import the data type definition from the specified header file.
ExportedExport the data type definition to a header file, which can be specified in the Header file field. If no value is specified for Header file, the header file name defaults to type.h. type is the data type name.
ImportedImport the data type definition from a header file, which can be specified in the Header file field. If no value is specified for Header file, the header file name defaults to type.h. type is the data type name.

Header file

Name of a C header file from which a data type definition is imported, or to which a data type definition is exported, based on the value of Data scope. If this field is specified, the specified name is used during code generation for importing or exporting. If this field is empty, the value defaults to type.h if Data scope equals Imported or Exported, or defaults to model_types.h if Data scope equals Auto.

Description

Describes the usage of the data type referenced by this alias.

Properties

Name

Description

BaseType

A string specifying the name of a standard or custom data type. (Base type)

DataScope

A string specifying whether the data type definition is imported from, or exported to, a header file during code generation. (Data scope)

Description

A string that describes the usage of the data type. Can be a null string. (Description)

HeaderFile

A string that specifies the name of a C header file from which a data type definition is imported, or to which a data type definition is exported, during code generation. (Header file)

Was this topic helpful?