Main Content

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:

  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.

Use Custom Mapping File Function

To use the custom mapping file function:

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

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

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

  5. In the Map Configuration section of the toolstrip, select Custom.

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

  7. Click Options and select the Update Model Automatically check box.

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

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

See Also

Classes

Functions

Related Topics