| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop Embedded Coder |
| Contents | Index |
| Learn more about Real-Time Workshop Embedded Coder |
| On this page… |
|---|
Registering User Data Types Using sl_customization.m Example User Data Type Customization Using sl_customization.m |
By default, MathWorks data types (such as real32_T and uint8_T) are used to define data in the generated code. If you prefer using your company-standard data types (such as DBL and U8), you can define user data types. To use this feature, you must register and create your data types so that the code generator can associate them with the corresponding MathWorks C/C++ data types. Then, the code generator will use your user data types in the generated code instead of the MathWorks C/C++ data types.
The Real-Time Workshop software automatically associates the MathWorks C/C++ data types with the equivalent ANSI[1] C/C++ data types. If you want to use only the default MathWorks C/C++ data types, you do not need to register and create your own data types.
To register user data types, use the Simulink customization file sl_customization.m. This file is a mechanism that allows you to use M-code to perform customizations of the standard Simulink user interface. The Simulink software reads the sl_customization.m file, if present on the MATLAB path, when it starts and the customizations specified in the file are applied to the Simulink session. For more information on the sl_customization.m customization file, see Customizing the Simulink User Interface in the Simulink documentation.
Once you have registered your user data types using sl_customization.m, you must create the Simulink.AliasType objects corresponding to your user data types. If your model references a user data type either directly (for example, in the output data type of a block) or indirectly (for example, a Simulink.Signal object data type is set to the user data type), you must create the corresponding Simulink.AliasType object before updating the model, running a simulation, or generating code. To create the Simulink.AliasType objects, you can:
Invoke the MATLAB function ec_create_type_obj to programmatically create all the required Simulink.AliasType objects
Create Simulink.AliasType objects one at a time by selecting Add > Simulink.AliasType in the Model Explorer
Create Simulink.AliasType objects one at a time by entering the MATLAB command userdatatype = Simulink.AliasType, where userdatatype is a user data type registered in sl_customization.m
To register user data type customizations, you create an instance of sl_customization.m and include it on the MATLAB path of the Simulink installation that you want to customize. The sl_customization function accepts one argument: a handle to a customization manager object. For example,
function sl_customization(cm)
As a starting point for your customizations, the sl_customization function must first get the default (factory) customizations, using the following assignment statement:
hObj = cm.slDataObjectCustomizer;
You then invoke methods to register your customizations. The customization manager object includes the following methods for registering Simulink user data type customizations:
addUserDataType(hObj, userName, builtinName, userHeader)
addUserDataType(hObj, userName, builtinName)
addUserDataType(hObj, userName, aliasTypeObj)
addUserDataType(hObj, userName, numericTypeObj)
addUserDataType(hObj, userName, fixdtString)
Registers the specified user-defined data type and adds it to the top of the data type list, as displayed in the Data type pull-down list in the Model Explorer.
userName — Name of the user data type
builtinName — MathWorks C/C++ data type to which userName is mapped
userHeader — Name of the user header file that includes the definition of the user data type
aliasTypeObj, numericTypeObj, or fixdtString — Simulink.AliasType, Simulink.NumericType, or fixdt to which userName is mapped
moveUserDataTypeToTop(hObj, userName)
Moves the specified user-defined data type to the top of the data type list, as displayed in the Data type pull-down list in the Model Explorer.
moveUserDataTypeToEnd(hObj, userName)
Moves the specified user-defined data type to the end of the data type list, as displayed in the Data type pull-down list in the Model Explorer.
removeUserDataType(hObj, userName)
Removes the specified user-defined data type from the data type list.
Your instance of the sl_customization function should use these methods to register user data types for your Simulink installation.
The Simulink software reads the sl_customization.m file when it starts. If you subsequently change the file, you must restart your Simulink session or enter the following command at the MATLAB command line to effect the changes:
sl_refresh_customizations
The sl_customization.m file shown in Example 1: sl_customization.m for User Data Type Customizations uses the following methods:
addUserDataType to register the user-defined data types MyInt16, MyInt32, MyBool, and fixdt(1,8)
moveUserDataTypeToTop to move MyBool to the top of the data type list, as displayed in the Data type pull-down list in the Model Explorer
removeUserDataType to remove the built-in data types boolean and double from the data type list
Example 1: sl_customization.m for User Data Type Customizations
function sl_customization(cm)
% Register user customizations
% Get default (factory) customizations
hObj = cm.slDataObjectCustomizer;
% Add custom types
hObj.addUserDataType('MyInt16', 'int16_T', '<mytypes.h>');
hObj.addUserDataType('MyInt32', 'int32_T', '<mytypes.h>');
hObj.addUserDataType('MyBool','boolean_T');
hObj.addUserDataType('fixdt(1,8)');
% Make MyBool first in the list
hObj.moveUserDataTypeToTop('MyBool');
% Remove built-in boolean and double from the list
hObj.removeUserDataType('boolean');
hObj.removeUserDataType('double');
endIf you include the above file on the MATLAB path of the Simulink installation that you want to customize, the specified customizations will appear in Model Explorer. For example, you could view the customizations as follows:
Start a MATLAB session.
Open Model Explorer, for example, by entering the MATLAB command daexplr.
Select Base Workspace.
Add an mpt signal, for example, by selecting Add > MPT Signal.
In the right-hand pane display for the added mpt signal, examine the Data type drop-down list, noting the impact of the changes specified in Example 1: sl_customization.m for User Data Type Customizations.

[1] ANSI is a registered trademark of the American National Standards Institute, Inc.
![]() | Applying Naming Rules to Identifiers Globally | Selecting User Data Types for Signals and Parameters | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |