Main Content

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 create a Simulink.AliasType object several ways.

  • Interactively create a data type alias using the Type Editor or Model Explorer.

  • Generate data type aliases that correspond to typedef statements in your external C code using the Simulink.importExternalCTypes function.

  • Programmatically create a data type alias using the Simulink.AliasType function described here.

Note

You must create data type aliases in the MATLAB® workspace or in a data dictionary. You cannot create an alias in a model workspace.

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

To interactively edit the properties of a Simulink.AliasType object, use the Type Editor.

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)'. To specify the characteristics of the type interactively, expand the Data Type Assistant and set Mode to Fixed point. For information about using the Data Type Assistant, see Specify Data Types Using Data Type Assistant.

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 object 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 object. Forbidding its use in alias types avoids creating aliases that have different base types depending on where they are used.

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.

Set the data scope to Imported or Exported to avoid potential MISRA C:2012 violations.

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

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

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 is 'Imported' or 'Exported', or defaults to model_types.h if DataScope is '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™.

Version History

Introduced before R2006a