Simulink.AliasType

Create alias for signal and parameter data type

Description

Use a Simulink.AliasType to create an alias of a built-in data type such as int8.

The name of the object is the alias. The data type to which an alias refers, such as int8, is the base type. Alias names cannot be:

  • Floating-point types: half, single, double

  • Integer types: int8, uint8, int16, uint16, int32, uint32, int64, or uint64.

  • Fixed-Point Designer™ types beginning with sfix, ufix, or flt.

You create the object in the base workspace or a data dictionary. To use the alias, you use the name of the object to set data types for signals, states, and parameters in a model.

Using aliases to specify signal and parameter data types can greatly simplify global changes to the data types that a model specifies. In particular, changing the data type of all signals, states, 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, states, 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, fixed-point data types, enumerated data types, Simulink.NumericType objects, and other Simulink.AliasType objects. The code that you generate from a model (Simulink Coder™) uses the alias only if you use an ERT-based system target file (Embedded Coder®).

Alternatively, to define and name a numeric data type, you can use an object of the class Simulink.NumericType.

Creation

You can use either the Model Explorer or MATLAB® commands to create a data type alias.

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).

To generate Simulink.AliasType objects that correspond to typedef statements in your external C code, consider using the Simulink.importExternalCTypes function.

To create a data type alias programmatically, use the Simulink.AliasType function described below.

Description

example

aliasObj = Simulink.AliasType returns a Simulink.AliasType object with default property values.

example

aliasObj = Simulink.AliasType(baseType) returns a Simulink.AliasType object and initializes the value of the BaseType property by using baseType.

Properties

expand all

For information about properties in the property dialog box of a Simulink.AliasType object, see Simulink.AliasType Property Dialog Box.

Name of the base data type that this alias renames, specified as a character vector or string scalar. You can specify the name of a standard data type, such as int8 or half, or the name of a custom data type, such as the name of another Simulink.AliasType object or the name of an enumeration.

To specify a fixed-point data type, you can use a call to the fixdt function, such as 'fixdt(0,16,7)'.

You can, with one exception, specify a nonstandard data type, e.g., a data type defined by a Simulink.NumericType object, by specifying the data type name. The exception is a Simulink.NumericType whose DataTypeMode 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.

Corresponds to Base type in the property dialog box.

Example: 'int8'

Example: 'myOtherAlias'

Data Types: char | string

Specification to generate or import the type definition (typedef) in the generated code (Simulink Coder), specified as 'Auto', 'Exported, or 'Imported'.

The table shows the effect of each option.

ValueAction
'Auto' (default)If no value is specified for HeaderFile, 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 HeaderFile, import the data type definition from the specified header file.
'Exported'Export the data type definition to a header file, which can be specified in the HeaderFile property. If no value is specified for HeaderFile, the header file name defaults to type.h. type is the data type name.
'Imported'Import the data type definition from a header file, which can be specified in the HeaderFile property. If no value is specified for HeaderFile, the header file name defaults to type.h. type is the data type name.

For more information, see Control File Placement of Custom Data Types (Embedded Coder).

Corresponds to Data scope in the property dialog box.

Custom description of the data type alias, specified as a character vector.

Corresponds to Description in the property dialog box.

Example: 'This type alias corresponds to a floating-point implementation.'

Data Types: char

Name of the header file that contains the type definition (typedef) in the generated code, specified as a character vector.

If this property is specified, the specified name is used during code generation for importing or exporting. If this property is empty, the value defaults to type.h if DataScope equals 'Imported' or 'Exported', or defaults to model_types.h if DataScope equals 'Auto'.

By default, the generated #include directive uses the preprocessor delimiter " instead of < and >. To generate the directive #include <myTypes.h>, specify HeaderFile as '<myTypes.h>'.

For more information, see Control File Placement of Custom Data Types (Embedded Coder).

Corresponds to Header file in the property dialog box.

Example: 'myHdr.h'

Example: 'myHdr'

Example: 'myHdr.hpp'

Data Types: char

Examples

collapse all

To create an alias for an enumerated type called SlDemoSign:

myEnumAlias = Simulink.AliasType('Enum: SlDemoSign');

To create an alias for a fixed-point data type by using a Simulink.AliasType object, set the BaseType property of the object by using a call to the fixdt function. The value of BaseType must be specified as a character vector.

For example, this code creates an alias for an unsigned fixed-point data type with word length 16 and fraction length 7.

myFixptAlias = Simulink.AliasType;
myFixptAlias.BaseType = 'fixdt(0,16,7)';

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a