Create and Use Custom Map Modes
You can create custom map modes to supplement the map modes that the Root Inport Mapper tool provides (see Choose Map Mode).
For a summary of the other steps involved in using the Root Inport Mapper tool, see Import and Mapping Workflow.
Create Custom Mapping File Function
Files for Custom Mapping Workflow
This example shows how to create a custom mapping file function if you do not want to use the map modes in the Root Inport Mapper tool. For example, consider creating a custom mapping file function if:
Your signal data contains a common prefix that is not in your model.
You want to map a signal explicitly.
When the data contains a signal name that does not match one of the block names, a custom mapping function is useful for block name mapping.
To access the files for this example, click the open button. This example folder contains these files:
BlockNameIgnorePrefixMap.m
BlockNameIgnorePrefixData.mat
ex_block_name_ignore_prefix.slx
Create Custom Mapping File Function
To create a custom mapping file function:
Create a MATLAB® function with these input parameters:
Model name
Signal names specified as a cell array of character vectors
Signals specified as a cell array of signal data
In the function, call the
function to create a variable that contains the mapping object (for an example, seegetRootInportMap
BlockNameIgnorePrefixMap.m
).Save and close the MATLAB function file.
Add the path for the new function to the MATLAB path.
Use Custom Mapping File Function
To use the custom mapping file function:
Open the model that you want to import data to (for example,
ex_block_name_ignore_prefix
).Open the Configuration Parameters dialog box for the model and select the Data Import/Export pane.
In the Load from workspace section, click Connect Inputs.
Import your signal (for example,
BlockNameIgnorePrefixData.mat
).In the Map Configuration section of the toolstrip, select Custom.
In the Custom Map text box, select the MATLAB function file (for example,
BlockNameIgnorePrefixMap.m
) using the browser.By default, this text box contains
slexcustomMappingMyCustomMap
, which is the custom function for Attaching Input Data to External Inputs via Custom Input Mappings.Tip
The Root Inport Mapper tool parses your custom code. Parsing reorders output alphabetically and verifies that data types are consistent.
Click Options and select the Update Model Automatically check box.
Click Check Map Readiness.
The model is compiled and the Root Inport Mapper tool gets updated.
To understand the mapping results, see Understand Mapping Results.
Save and close the model.
After you save the mapping definition for a model, you can automate data loading. The next time that you load input data of the same signal group into the workspace, the model uses the mapping definition during simulation. For more information, see Alternative Workflows to Load Mapping Data.
Custom Map Modes Similar to Simulink Modes
If your custom map mode is similar to a Simulink® map mode, use the getSlRootInportMap
function in
your custom mapping file function to perform the data mapping.
For an example of a custom mapping function that uses this function, see Using Mapping Modes with Custom-Mapped External Inputs.
Command-Line Interface for Input Variables
Use the
function to supply a set of input variables to:getInputString
The
commandsim
A list of input variables that you can paste in the Configuration Parameters > Data Import/Export > Input parameter
See Also
Classes
Simulink.io.FileType
|Simulink.io.BaseWorkspace
|Simulink.io.MatFile
|Simulink.io.MDF
|Simulink.io.PluggableNamespace
|Simulink.io.SignalBuilderSpreadsheet
|Simulink.io.SLDVMatFile
|sltest.io.SimulinkTestSpreadsheet
(Simulink Test)
Functions
exportImpl
|getFileTypeDescription
|Simulink.io.FileType.isFileSupported
|loadImpl
|loadAVariableImpl
|validateFileNameImpl
|whosImpl