Import and Map Root-Level Inport Data

Root Inport Mapping

To import, visualize, and map signal and bus data to root-level inports, use the Root Inport Mapping tool. For alternative ways to import data, see Techniques for Importing Signal Data.

To start Root Inport Mapping, in the Simulink® Editor for your model, click the Edit Input button in Simulation > Model Configuration Parameters > Data Import/Export. The model name displays in the top left of the tool.

Importing and Mapping Workflow

  1. Identify the signals you want to import and map to the model root-level inports (see Identify Signal Data to Import and Map).

  2. Import data (see Import Signal and Bus Data).

  3. Visualize data (see View and Inspect Signal Data).

  4. Determine how you want to map the data, for example, by block path or signal name, (see Select Map Mode).

  5. Select options to map signals (see Set Options for Mapping).

  6. Map the data (see Map Data).

  7. Save data for future reference or for others to use (see Export Data).

  8. Save the current Root Inport Mapping scenario for future reference or to share with others (see Work with Scenarios).

To create a custom mapping file function to map data to root-level inports, see Create Custom Mapping File Function.

Identify Signal Data to Import and Map

You can import data from these sources.

Data SourceDescription

Base workspace

You can selectively import from the base workspace. If there are overlapping signal names, the most recently imported signal overwrites the signal already loaded in the Root Inport Mapping tool. For more information on supported data formats, see Supported Base Workspace and MAT-File Formats.

Data files

You can selectively import signals contained in MAT-files and Microsoft® Excel® files. Each time you import the contents of one of these files, the contents overwrite all existing data already loaded in the Root Inport Mapping tool.

Supported Base Workspace and MAT-File Formats

The Root Inport Mapping tool supports these MATLAB® data types or formats.

Data FormatsBlock NameBlock PathSignal NamePort OrderCustom

Simulink.SimulationData.Dataset

Timeseries (MATLAB and Simulink)

(only for Simulink timeseries)

Simulink.SimulationData.Signal

Stateflow.SimulationData.State

Structure with Time, Structure Without Time

     

Data Array

     

Time Expression

     

Array of Buses

 

Asynchronous Function-call Signals

 

For example, a signal data MAT-file with three signals (signal1, signal2, and signal3) with block path specified might have workspace variables as shown in this code sample. This file has signals that have signal names, block names, block paths, and port order index values, which enables to map the data using Signal Name, Block Name, Block Path, or Port Order mapping mode. If there are corresponding root-level inports with corresponding port order, signal names, or block paths, the tool maps the signal to those ports.

signal1 = 

  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
         Name: 'signalGain5'
    BlockPath: [1x1 Simulink.SimulationData.BlockPath]
     PortType: 'outport'
    PortIndex: 1
       Values: [1x1 timeseries]

  Methods, Superclasses
>> signal2

signal2 = 

  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
         Name: 'signalGain10'
    BlockPath: [1x1 Simulink.SimulationData.BlockPath]
     PortType: 'outport'
    PortIndex: 1
       Values: [1x1 timeseries]

  Methods, Superclasses
>> signal3

signal3 = 

  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
         Name: 'signalGain15'
    BlockPath: [1x1 Simulink.SimulationData.BlockPath]
     PortType: 'outport'
    PortIndex: 1
       Values: [1x1 timeseries]

  Methods, Superclasses

Notes for MAT-files and base workspace:

  • Only one Simulink.SimulationData.Dataset per base workspace or MAT-file can load. If there are multiple data sets of this type, the first data set listed alphabetically loads.

  • The number of signals with the formats structures, with and without time, must be the same as the number of model inports, enable ports, and trigger ports.

  • Data arrays are matrices. If you have a data array where the number of columns-1 is equal to the sum of the port widths of all root-level input port blocks in the model. the Root Inport Mapping tool tries to map this data for the entire model. In this case, you can choose only the Port Order mapping method. If the number of columns-1 does not equal the number of root-level inports (including trigger and enable ports), the Root Inport Mapping tool tries to map the data array to a single inport. In this case, you can choose any of the mapping methods.

  • If your MAT-file or base workspace contains a format that Simulink does not support, the tool ignores it.

  • If you have time series data with enumeration, and the enumeration class is not on your MATLAB path, the tool ignores that time series data.

Supported Excel File Formats

The Root Inport Mapping tool supports Microsoft Excel spreadsheets only for Windows® systems.

For Microsoft Excel spreadsheets:

  • The tool interprets each worksheet as a Simulink.SimulationData.Dataset data set.

  • Each worksheet name must be a valid MATLAB variable name.

  • The tool interprets the first row of a worksheet as signal names. If you do not specify a signal name, the tool assigns a default one using the format Signal#.

  • If all columns do not have signal names, the tool assigns signal names using the format Signal#, where # increments with each additional signal.

  • All signal-name columns must be filled in. If there are empty signals, the tool returns an error at import.

  • The tool interprets the first column as time. In this column, the time values must increase.

  • The tool interprets the remaining columns as signals.

Import Signal and Bus Data

You can import signal and bus data. Before you can set up bus data, you first need to set up bus data.

Set Up Bus Data

You can import and map bus data as well as signal data. For more information on buses, see Bus Objects.

  1. In the MATLAB workspace, create or load a bus object for the bus data you want to import and map.

  2. If creating a bus object in the base workspace, save the bus object definition to a MAT-file, for example, d_myBusObj.mat.

  3. Have a different MAT-file that contains the bus data you want to import for the bus object. This can be an existing MAT-file that already contains a MATLAB struct or Simulink.TSArray, or you can create the bus in the base workspace and save it to a MAT-file.

  4. Set up the model to load the bus object.

Continue to Import Data.

Import Data

Before you can import data, you must set up the signals you want to import. See Identify Signal Data to Import and Map.

  1. In the Simulink model you want to import the signal or bus data to, open the Configuration Parameters dialog box.

  2. In the Data Import/Export pane, in the Load from workspace section, click Edit Input.

  3. In the Import dialog box, select the data source, Base workspace or File.

    • Select Base workspace to display a list of base workspace variables that you can import. Select the variables you want to import and click OK.

    • Select File to browse to the MAT-file or Excel file that contains the signals you want to import, click Open to return to the Import dialog box, then click OK.

    The Input dialog box displays the contents of the base workspace or file.

  4. Select the data that you want to import, and then click OK.

    The Root Inport Mapping tool updates with the imported data.

Choose your next action:

Import from Other Sources

You can also use the Root Inport Mapping tool to import signals from other sources:

View and Inspect Signal Data

After you have imported signal or bus data (see Import Signal and Bus Data), you can view and inspect signal data.

  1. To plot the signal, click the check box next to the signal. If the format is a bus, click the expander ( ) to see and select the elements of the bus.

  2. Explore the plots using the Measure and Zoom & Pan sections of the toolstrip.

    • In the Measure section, use the Data Cursors button to display one or two cursors for the plot. These cursors display the T and Y values of a data point in the plot. Click a point on the line to view a data point.

    • In the Zoom & Pan section, select how you want to zoom and pan the signal plots. Zooming is only for the selected axis.

      To...Click...

      Zoom in along the T and Y axes.

      Zoom in along the time axis. After selecting the icon, on the graph, click and hold the left mouse button and drag the mouse to select an area to enlarge.

      Zoom in along the data value axis. After selecting the icon, on the graph, click and hold the left mouse button and drag the mouse to select an area to enlarge.

      Zoom out from the graph.

      Fit the plot to the graph. After selecting the icon, click the graph to enlarge the plot to fill the graph.

      Pan the graph up, down, left, or right. After selecting the icon, on the graph, click and hold the left mouse button and move the mouse to the area of the graph that you want to view.

  3. To view the properties of a signal, click inside the plot area. The signal properties update:

To select a mapping mode, see Select Map Mode.

Select Map Mode

Map data to root-level ports using one of these methods:

GoalMap Mode

Assign signals to ports according to the name of the root-inport block. If the name of a signal or bus element matches the name of a root-inport block, the data is mapped to the corresponding port.

Block Name

Assign signals to ports according to the block path of the root-inport block. If the block path of a signal matches the block path of a root-inport block, the data is mapped to the corresponding port.

Block Path

Assign signals to ports according to the name of the signal on the port. If the signal name of a data element matches the name of a signal at a port, the signal is mapped to the corresponding port.

Signal Name

Assign sequential port numbers to the imported data, starting at 1 and map this signal to the corresponding inport.

  • If there is more data than inports, the remaining data are mapped first to enable and then trigger inports.

  • If the data is not in the form of a data set, the data is processed in the order in which it is passed or parsed from the data file, i.e., the order in which the data appears in the file.

Port Order

Assign signals to ports according to the definitions in a custom file.

Custom

    Tip   When identifying signals to import, consider using a naming convention for signals and buses such that this grouping of data (signal group) is interchangeable. For example, you can have two MAT-files whose data has different values but the same variable names. This convention allows you to quickly switch the groups of input data into and out of a model.

Choose your next action:

Set Options for Mapping

If you want to set up mapping options, in the Root Inport Mapping toolstrip, click Options. To map the signals, see Map Data.

GoalOption

Compile the model and check the data types of root-level inports and imported data.

Compile. See Understand Mapping Results. If the comparison data is inherited from the connected block, a warning appears.

If you do not select this option, the tool maps the imported data to the root-level inport but does not compile the model. When you select this option, the tool compares the data and inport parameters to the root-level port and displays the results.

Import bus data that is only partially defined.

Allow partial. Select this option to make sure that any partially specified bus data you import maps properly to root-level imports.

Map Data

After you have imported signals or buses (see Import Signal and Bus Data), you can map data.

  • In the Root Inport Mapping toolstrip, click Map.

    The results of a signal mapping display on the Input Map tab.

    • The Input Map tab lists the input data and the status of the mapping.

    • The mapping definition for the input data is applied to the model.

After you save and close the model, the next time you load input data of the same signal group into the workspace, the model uses the mapping definition during simulation.

After you save the mapping definition for a model, you can automate data loading. For more information, see Alternative Workflows to Load Data.

Understand Mapping Results

When you complete the import and map process, the Root Inport Mapping Input Map tool displays the results in the status area.

StatusCompileContinue Without Compile

The properties of the mapped data and the inport are appropriate for simulation.

The data type, dimension, and signal type properties of the data and inport are compatible.

N/A

Comparison of data and root-level port data type, dimension, and signal type properties cannot determine if there is a match. If you do not compile before mapping, the tool cannot evaluate whether all the data types match unless you explicitly specify the inport data types. Make sure these block parameters are set correctly:

  • Inport block parameter Data type is not set to Inherit:auto.

  • Inport block parameter Dimension is not set to -1.

  • Inport block parameter Complexity cannot be auto.

The properties of the mapped data and the inport are not appropriate for simulation.

One or more of the data type, dimensions, and signal type properties of the data and inport are not compatible.

Root-level input ports that have not been mapped display as empty ([]).

This figure shows mapping successes and failures.

In the Root Inport Mapping tool, clicking Map selects the Input check box in the Data Import/Export pane of the model Configuration Parameters dialog box. Mapping also sets the value to the imported data variables. To apply the changes to the model configuration, in the Data Import/Export pane, click OK in the Configuration Parameters dialog box.

To inspect the imported data, you can:

  • Connect the output to a scope, simulate the model, and observe the data.

  • Log the signals, and use the Simulation Data Inspector tool to observe the data.

Select an item in the Input Map tab to highlight the associated Inport block. If there are warnings or failures, the Inport block associated with the data appears highlighted in the model.

  • Failures display as yellow Inport blocks outlined with bold red.

  • Warnings display as yellow Inport blocks outlined in orange.

  • Successes display as normal Inport blocks outlined with blue.

The figures shows that when you select the Counter block name in the Input Map tab, the Counter block in the model is highlighted. The highlighting indicates an error.

Use the Comparison Tool to evaluate your next action. The Comparison Tool shows the properties for the root-level inport and the signals you are trying to map to the inport. You can tell from this table if there is a mismatch that prevents the mapping. For example, if there is a mismatch, you can update the imported signals or edit the root-level inport. When you are done, reimport the data to map it.

To investigate warnings and failures, click the line item you want to inspect in the Input Map tab. The Comparison Tool lists the selected variable, including the field name, input data, and root-level inport.

    Note:   When the input is a bus, click the levels of the bus object to drill down to the individual elements in the bus.

In some cases, the Comparison Tool shows a warning or error, but your investigation of the elements indicates that there is no problem with mapping the data. In these cases, if you did not select the Compile check box in the Options menu, select it and click Map again.

    Tip   Each time you click a non-green status item, a new Comparison Tool instance appears. To dock all Comparison Tool instances in one window, click the Dock button .

For more information on the Comparison Tool, see Comparing Files and Folders.

Export Data

To save the data you have been working on, export it to the base workspace or a data file.

  1. In the Root Inport Mapping toolstrip, click Export.

  2. In the Export dialog box, select:

    • Base workspace to export the data to the base workspace. If the base workspace contains signals with the same name, the tool overwrites those signals with the exported signal.

    • File to browse to a writable folder in which to save the signals file. Enter a MAT-file or Microsoft Excel file name. If the file exists and contains signals with the same name, the tool overwrites those signals with the exported signal.

Work with Scenarios

The Root Inport Mapping tool uses scenarios to save a snapshot of the current state of the imported and mapped signals in an MLDATX file. A scenario file contains information about:

  • Location of signal files (MAT-file or Microsoft Excel files)

  • Location of the model

  • Mapping mode

  • Mapping options

  • Mapped state

When sharing scenario files, include the scenario file and signal files (MAT-file or Microsoft Excel. Place the signal files in the last known location or the MATLAB path.

Use the Root Inport Mapping tool to create new scenarios, save scenarios, and load previously saved scenarios.

Save Scenarios

You can save a scenario when the Save icon turns blue or when the model name in the title bar is has an asterisk (*).

  1. In the Root Inport Mapping toolstrip, select Save > Save As.

  2. In the Save As dialog box, browse to a writable folder, specify a scenario file name, and then click Save.

    • Click Yes to save the signals and the scenario file.

      If you loaded signals from the base workspace and have not saved the signals from the scenario, the tool prompts you to save the signals to a MAT-file. If a MAT-file is already associated with the scenario, the tool appends the base workspace variables to this file.

To save a scenario to an existing file (the file from which the scenario was last loaded):

  1. In the Root Inport Mapping tool toolbar, click Save.

  2. Browse to the MLDATX file in which to save the scenario, then click Save.

    If you have not saved the signals from the scenario, the tool prompts you to save the signals to a MAT-file.

    To...Click...

    Overwrite the existing MLDATX file.

    Yes

    Exit the dialog. The tool does not save the scenario.

    No

Open Existing Scenarios

You can open previously saved scenario files in one of the following ways:

  • Double-click the previously saved scenario file (*.mldatx). The Root Inport Mapping tool opens and loads the model. Alternatively, right-click the file and select Open.

    • When loading the scenario file, the tool first looks for the associated model and MAT-file or Microsoft Excel file in the last known location, then on the MATLAB path. An error occurs if the tool cannot find the model or signal files in these two locations.

    • If the previously saved scenario has mapped signals, then when you open the scenario, the tool applies the mapping and adds the signals to the base workspace so that you can simulate the model.

  • Open the Root Inport Mapping tool for the model, click Open, and select the previously saved scenario file.

If the model is already open, the new scenario overwrites the existing scenario for the model. If there are unsaved changes in the open scenario, the tool prompts you:

To...Click...

Save the existing scenario and associated data before loading the new scenario.

Yes

Open the new scenario without saving the existing scenario. This option also removes the data in the existing scenario.

No

Create New Scenarios

To create a new scenario, click New. If you are working in another scenario, the Root Inport Mapping tool displays the message:

To...Click...

Open a new scenario. This action removes the existing scenario without saving it.

OK

Cancel. Then use the Save button to save the existing scenario first, and click the New button again to open a new scenario.

Cancel

Convert Test Harness Model to Harness-Free Mode

If you have a model that uses the Signal Builder block and want to convert to using the Root Inport Mapping tool, export the signals from that block to the Root Inport Mapping tool. The workflow is:

  1. In the model, export signals from the Signal Builder block to a variable in the base workspace.

  2. Import the variables from the base workspace to the Root Inport Mapping tool.

  3. Remove the Signal Builder block from the model.

  4. Add Inport blocks to the model. The number of Inport blocks must equal the number of output lines from the Signal Builder block you removed.

  5. Connect the Inport blocks to these lines.

The following example describes how to replace the Signal Builder block in the sldemo_autotranssldemo_autotrans model.

Converting Harness-Driven Models to Use Harness-Free External Inputs

This example shows how to convert a harness model that uses a Signal Builder block as an input to a harness-free model with root inports. The example collects data from the harness model and stores it in MAT-files, for use by the harness-free model. After storing the data, the example removes the Signal Builder block from the harness model and adds root inports to create a harness-free model. Then, the data in the MAT-files is mapped to the root inports of the model.

Save Harness Data to MAT-Files

Before converting the model to be harness-free, capture the test cases in the harness.

For this example, you will modify the model sldemo_autotranssldemo_autotrans from the Modeling an Automatic Transmission Controller example.

Open the example model. In the MATLAB Command Window type sldemo_autotrans.

Use MATLAB function slexAutotransRootInportsSaveActiveGroupslexAutotransRootInportsSaveActiveGroup to save the Signal Builder block data of the active group into a MAT-file. At the command line type slexAutotransRootInportsSaveActiveGroup('slexAutotransRootInport','ManeuversGUI'). This function creates a MAT-file in the current directory with the same name as the active group. The function slexAutotransRootInportsSaveActiveGroupslexAutotransRootInportsSaveActiveGroup has been provided with this example.

Remove the Signal Builder Block

Remove the Signal Builder block named ManeuversGUI and replace it with two inports.

  1. Delete the Signal Builder block named ManeuversGUI.

  2. Open the Simulink Library Browser and select Commonly Used Blocks.

  3. Drag and drop two input ports from the Library Browser to the model.

  4. Connect the input ports to the lines previously connected to the Signal Builder block.

  5. Rename the inport ports. Name the input port connected to the Throttle line Throttle. Name the input port connected to the BrakeTorque line Brake.

Save the model as slexAutotransRootInportsExample1.slx or use the example slexAutotransRootInportsExample.slx.

The remaining steps of this example use the model slexAutotransRootInportsExample.slx. If you saved the model with a different name use your model name in the steps going forward.

Set Up Harness-Free Inputs

Now that the model is harness-free, set up the inputs that you already saved (See "Save Harness Data to MAT-Files").

From the Simulation->Model Configuration Parameters->Data Import/Export pane, click the Edit Input button.

Map Signals to Root Inport

The Root Inport Mapping tool opens.

This example uses this tool to set up the model inputs from the MAT-file and map those inputs to an input port, based on a mapping algorithm. To select the MAT-file that contains the input data, click the Import button on the Root Inport Mapping toolbar. On the Import popup, select the File radio button and click the Open Folder button. In the browser, select the MAT-file that you saved earlier.

Select a Mapping Mode

Once you select the MAT-file slexAutotransRootInportPassingManeuver.mat that contains the input data, determine the root input port to which to send input data. Simulink matches input data with input ports based on one of five criteria:

  • Port Order - Maps in the order it appears in the file to the corresponding port number.

  • Block Name - Maps by variable name to the corresponding root inport with the matching block name.

  • Signal Name - Maps by variable name to the corresponding root inport with the matching signal name.

  • Block Path - Maps by the BlockPath parameter to the corresponding root inport with the matching block path.

  • Custom - Maps using a MATLAB function.

Earlier in this example, you used the slexAutotransRootInportsSaveActiveGroup to save input data to variables of the same name as the harness signals Throttle and Brake, and you added input ports with names matching the variables. Given the set of conditions for the input data and the model input ports, the best choice for a mapping criteria is Block Name. Using this criteria, Simulink tries try to match input data variable names to the names of the input ports. To select this option:

  1. Click the Block Name radio button.

  2. Click the Options button and select Compile from the dropdown. This will provide some verification on the mapping.

  3. Click the Map button.

When compiling the data, Simulink evaluates inports against the following criteria to determine whether or not there is a compatibility issue. The status of this compatibility is reflected by the table colors green, orange, or red. Clicking a cell in the table which has orange or red color will open the Comparison Tool for further inspection.

  • Data Type - Double, single, enum, ....

  • Complexity - Real or complex

  • Dimensions - Signal dimensions vs port dimensions

Finalize the Inputs to the Model

Review the results of the mapping compatibility. The Map action has loaded the data that was mapped to the input ports from the MAT-file to the base workspace. Simulink sets the Model Configuration Parameters->Data Import/Export->External Input edit box with the proper comma separated list of inputs. To apply the changes to the model, in the Configuration Parameters dialog, click Apply.

Simulating the Model

With the changes applied you can now simulate the model and view the results. Click the Play button on the model. To view the results of the simulation, double-click the Scope Block PlotResults.

Import Test Vectors from Simulink Design Verifier Environment

You can import and map Simulink Design Verifier test vectors. The following workflow shows how you can use the Simulink Design Verifier sldvsimdata function to convert a Simulink Design Verifier test structure to a Simulink.SimulationData.Dataset object. This workflow requires a Simulink Design Verifier license.

  1. Load a MAT-file that contains a Simulink Design Verifier test vector structure. sldvData. For example:

    load sqrt_sldvdata.mat
  2. Use the sldvsimdata function to convert a test vector structure to a Simulink.SimulationData.Dataset object that the Root Inport Mapping tool supports. This example converts the first test case in sldvData. For example:

    sldvDataConverted = sldvsimdata(sldvData,1)
  3. Save the Simulink.SimulationData.Dataset object aSLDs to a MAT-file. For example:

    save sldvData.mat sldvDataConverted

You can now import sldvData.mat into the Root Inport Mapping tool as you do any support MAT-file. For more information on importing signals, see Import Signal and Bus Data.

Alternative Workflows to Load Data

After saving the mapping definition to a model, you can automate data loading and/or simulation. Consider one of the following methods.

Command Line or Script

To load data and simulate the model from the MATLAB command line, use commands like:

load('signaldata.mat');
simout = sim('model_name');

To automate testing and load different signal groups, consider using a script.

For example, the following example code creates timeseries data and simulates a model after loading each signal group. It:

  1. Creates signal groups with variable names In1, In2, and In3, and saves these variables to MAT-files.

  2. Simulates a model after loading each signal group.

    Note:   The variable names must match the import data variables in the Data Import/Export > Input parameter of the Configuration Parameters dialog box.

% Create signal groups
fileName = 'testCase';
for k =1 :3
    
    % Create the timeseries data
    var1 = timeseries(rand(10,1));
    var2 = timeseries(rand(10,1));
    var3 = timeseries(rand(10,1));
    
    % Save the data 
    save([fileName '_' num2str(k) '.mat' ],'var1','var2','var3');
end
clear all

% After mapping and saving the model loop over signal groups and simulate
% Set the filename to append testcase # to
fileName = 'testCase';
% Loop backwards to preallocate
for k=3:-1:1
   % Load the MAT-file.
   load([fileName '_' num2str(k) '.mat' ]);
   
   % Simulate the model
   simOut{k} = sim('model_name');
end

Use the PreLoadFcn Pane

If you are satisfied with the data and mapping, you can set up your model to automatically load a MAT-file of the same signal group by calling the load function in the model PreLoadFcn model property node.

  1. After saving the MAT-file, in the Simulink editor, select File > Model Properties > Model Properties.

  2. In the Model Properties window, select the PreLoadFcn node.

  3. Enter a load function to load the signal data MAT-file. For example,

    load d_signal_data.mat;
  4. Click OK and save the model.

Create Custom Mapping File Function

Create a custom mapping file function if you do not want to use the mapping modes in the Root Inport Mapping tool to map your data to root-level input ports. 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 explicitly map a signal.

The custom mapping file function is also useful if you want to map by block name, but the data contains a signal whose name does not match one of the block names.

See these files in matlabroot\help\toolbox\simulink\examples for examples.

FileDescription

BlockNameIgnorePrefixMap.m

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

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 Attaching Input Data to External Inputs via Custom Input MappingsAttaching Input Data to External Inputs via Custom Input Mappings.

Follow these general steps to create a custom mapping file function:

  1. Create a MATLAB function with the following input parameters:

    • Model name

    • Signal names specified as a cell array of strings

    • 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 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 Edit Input.

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

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

      Tip   The Root Inport Mapping 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 compiles and the Root Inport Mapping tool updates.

    To understand the mapping results, see Understand Mapping Results.

  9. Save and close the model.

The next time you load input data of the same signal group into the workspace, the model uses the mapping definition during simulation.

After you save the mapping definition for a model, you can automate data loading. For more information, see Alternative Workflows to Load Data.

Custom Mapping Modes Similar to Simulink Modes

If you have a custom mapping mode that is similar to one of the Simulink mapping modes, you can use the getSlRootInportMap function in your custom mapping file function.

For an example of a custom mapping function that uses this function, see Using Mapping Modes with Custom-Mapped External InputsUsing Mapping Modes with Custom-Mapped External Inputs.

Command-Line Interface for Input Variables

Use the getInputString function to programmatically supply a set of input variables to the sim command or to a list of input variables that you can manually paste in the Configuration Parameters > Data Import/Export > Input parameter.

Was this topic helpful?