Main Content

Simulink.AliasType

Create alias for signal and parameter data type

Description

Use aSimulink.AliasTypeto create an alias of a built-in data type such asint8

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

  • Floating-point types:一半,single,double

  • Integer types:int8,uint8,int16,uint16,int32,uint32,int64, oruint64

  • Fixed-Point Designer™ types beginning withsfix,ufix, orflt

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.NumericTypeobjects, and otherSimulink.AliasTypeobjects. 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®).

一个lternatively, to define and name a numeric data type, you can use an object of the classSimulink.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 ExplorerModel Hierarchypane, selectBase 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一个ddmenu, selectSimulink.AliasType

    Simulink software creates an instance of aSimulink.AliasTypeobject and assigns it to a variable named一个liasin 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 theNamefield on the Model ExplorerContentspane.

  4. On the Model ExplorerDialogpane, in theBase typefield, 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 isdouble(the default).

生成Simulink.AliasTypeobjects that correspond totypedefstatements in your external C code, consider using theSimulink.importExternalCTypesfunction.

To create a data type alias programmatically, use theSimulink.AliasTypefunction described below.

Description

example

aliasObj = Simulink.AliasType返回一个Simulink.AliasTypeobject with default property values.

example

aliasObj = Simulink.AliasType(baseType)返回一个Simulink.AliasTypeobject and initializes the value of theBaseTypeproperty by usingbaseType

Properties

expand all

For information about properties in the property dialog box of aSimulink.AliasTypeobject, seeSimulink.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 asint8or一半, or the name of a custom data type, such as the name of anotherSimulink.AliasTypeobject or the name of an enumeration.

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

You can, with one exception, specify a nonstandard data type, e.g., a data type defined by aSimulink.NumericTypeobject, by specifying the data type name. The exception is aSimulink.NumericTypewhoseDataTypeModeisFixed-point: unspecified scaling

Note

Fixed-point: unspecified scaling是一个部分specified type whose definition is completed by the block that uses theSimulink.NumericType。Forbidding its use in alias types avoids creating aliases that have different base types depending on where they are used.

Corresponds toBase typein 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.

Value 一个ction
'Auto'(default) If no value is specified forHeaderFile, export the type definition tomodel_types.h, wheremodelis the model name. If you have an Embedded Coder license, and you have specified a data type replacement, then export the type definition tortwtypes.h

If a value is specified forHeaderFile, 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 theHeaderFileproperty. If no value is specified forHeaderFile, the header file name defaults totype。htypeis the data type name.
'Imported' Import the data type definition from a header file, which can be specified in theHeaderFileproperty. If no value is specified forHeaderFile, the header file name defaults totype。htypeis the data type name.

For more information, seeControl File Placement of Custom Data Types(Embedded Coder)

Corresponds toData scopein the property dialog box.

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

Corresponds toDescriptionin 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 totype。hifDataScopeequals'Imported'or'Exported', or defaults tomodel_types.hifDataScopeequals'Auto'

By default, the generated#includedirective uses the preprocessor delimiter"instead of<and>。生成的指令#include , specifyHeaderFileas''

For more information, seeControl File Placement of Custom Data Types(Embedded Coder)

Corresponds toHeader filein 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 calledSlDemoSign:

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

To create an alias for a fixed-point data type by using aSimulink.AliasTypeobject, set theBaseTypeproperty of the object by using a call to thefixdtfunction. The value ofBaseTypemust be specified as a character vector.

For example, this code creates an alias for an unsigned fixed-point data type with word length16and fraction length7

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