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 a 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

If you do not want to use the map modes in the Root Inport Mapper tool, create a custom mapping file function. 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.

For examples, see these files in the folder matlabroot/help/toolbox/simulink/examples (open).

FileDescription

BlockNameIgnorePrefixMap.m

Custom mapping file function that ignores the prefix of a signal name when importing signals

BlockNameIgnorePrefixData.mat

MAT-file of signal data to be imported

ex_BlockNameIgnorePrefixExample

Model file into which you can import and map data

In addition, see the example Using Mapping Modes with Custom-Mapped External Inputs.

To create a custom mapping file function:

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

  2. In the function, call the getRootInportMap function to create a variable that contains the mapping object (for an example, see BlockNameIgnorePrefixMap.m).

  3. Save and close the MATLAB function file.

  4. Add the path for the new function to the MATLAB path.

To use the custom mapping file function:

  1. Open the model that you want to import data to (for example, ex_BlockNameIgnorePrefixExample).

  2. Open the Configuration Parameters dialog box for the model and select the Data Import/Export pane.

  3. In the Load from workspace section, click Connect Input.

  4. Import your signal (for example, BlockNameIgnorePrefixData.mat).

  5. In the MAP TO MODEL section of the toolstrip, click Custom.

  6. In the Custom 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 the Attaching Input Data to External Inputs via Custom Input Mappings example.

    Tip

    The Root Inport Mapper tool parses your custom code. Parsing reorders output alphabetically and verifies that data types are consistent.

  7. Click Options and select the Compile check box.

  8. Click Map.

    The model is compiled and the Root Inport Mapper tool gets updated.

    To understand the mapping results, see Understand Mapping Results.

  9. 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 Mapping Modes Similar to Simulink Modes

If your custom mapping mode is similar to a Simulink® mapping 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 getInputString function to supply a set of input variables to:

  • The sim command

  • A list of input variables that you can paste in the Configuration Parameters > Data Import/Export > Input parameter

Related Examples

More About