This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Map Signal Data to Root Inports

After you import data, map signal data to root inports by selecting map modes and options and selecting data.

For a summary of the other steps involved in using the Root Inport Mapper tool, see Import and Mapping Workflow.

Select Map Mode

To map signal data to root-level ports, use one of these map modes in the MAP TO MODEL section of the Root Inport Mapper toolstrip. The mapping mode you select from the toolstrip, such as Block Name or Port Order, is maintained between MATLAB® sessions and models. You do not have to select the map mode each time you want to map signal data to root inports.

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. Map signals to the corresponding inports.

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

If the data is not in the form of a dataset, it is processed in the order in which it appears in the data file.

Port Order

Assign signals to ports according to the definitions in a custom file. To create a custom mapping mode, see Create and Use Custom Map Modes.

Custom

Set Options for Mapping

If you want to set up mapping options, in the MAP TO MODEL section on the Root Inport Mapper toolstrip, click Options. The option you select from the toolstrip, such as Update Model or Allow Partial, is maintained between MATLAB sessions and models. You do not have to select the option each time you want to map signal data to root inports.

To map the signals, see Map Data.

GoalOption

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

Update Model. Compare the signal data and inport parameters to the root-level port and display the results. If you do not select this option, the tool maps the imported data to the root-level inport but does not compile the model.

Use strong data typing when mapping data from spreadsheets.

Use Strong Data Typing with Spreadsheets. Clear this check box to allow the Root Inport Mapper tool to automatically convert spreadsheet input signals to the data types of the corresponding root inports. The Root Inport Mapper tool can cast the spreadsheet data to only these data types: double, single, int8, uint8, int16, uint16, int32, uint32. If you select this check box or if the root inport is not one of these data types, you may receive a data type mismatch error.

Import bus data that is only partially defined.

Allow partial. Confirm that any partially specified bus data you import maps properly to root-level inports.

Identify unassigned root inports and detect incomplete input data sets.

Notify of Missing Signals. Show inputs with missing signals.

Select Data to Map

To specify a subset of scenarios to map, click the down arrow on the Map to Model button. You can choose different mapping modes for different scenarios.

GoalOption

Map all the scenario datasets (default).

Map All

Map the datasets of the scenarios currently selected in the SCENARIO DATASET section.

Map Selected

Map the disconnected datasets.

Map Unconnected

Map datasets that previously failed a mapping.

Map Failed

Map datasets that previously caused warnings.

Map Warned

Map Data

After you import signals or buses, you can map data.

  1. On the Root Inport Mapper toolbar, click Map to Model.

    The results of a signal mapping appear in the SCENARIO DATASET tab.

  2. In the FILE section, click a data set to see the mapping results

    • The MAPPING SUMMARY section 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, when you load input data of the same scenario to the workspace, the model uses the mapping defined for that scenario.

For an example of mapping signal data to root-level inputs, see Converting Harness-Driven Models to Use Harness-Free External Inputs.

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

Understand Mapping Results

When you complete the import and map process, the MAPPING SUMMARY section displays the results in the status area. The results depend on whether you select the Compile option when you set up the mapping.

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.

Not applicable

Comparison of data and root-level port data type, dimension, and signal type properties cannot determine whether 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. Confirm that you set these block parameters correctly:

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

Inport block parameter Dimension is not set to -1.

Inport block parameter Signal type cannot be auto.

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

One or more of the data types, dimensions, or signal types of the signal data are not compatible with the root-level inport.

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

This figure shows mapping successes and failures.

In the Root Inport Mapper tool, clicking Mark for Simulation selects the Input check box in the Data Import/Export pane in the model Configuration Parameters dialog box. It 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.

If your model uses configuration references to reference configuration sets, you cannot mark the model for simulation. To use this data to simulate the model with the Root Inport Mapper tool, use the Model Explorer to activate a configuration set first.

This graphic illustrates the application of the changes to the model configuration for the model in Map Data.

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.

To highlight the Inport block that is associated with the signal, select an item in the MAPPING SUMMARY section. The selected Inport block is outlined with blue.

Use the Comparison Tool to evaluate your next action. The Comparison Tool shows the properties for the root-level inport and the signals that you are trying to map to the inport. You can tell from this table whether 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, in the MAPPING SUMMARY section, click the line item that you want to inspect. 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 see the individual elements in the bus.

Sometimes 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 from the Options menu, select it and click Map again.

Tip

Each time you click a nongreen 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 Compare Files and Folders and Merge Files (MATLAB).

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_autotrans from the Modeling an Automatic Transmission Controller example.

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

Exporting Signal Builder Block Groups

You can export data that defines Signal Builder block signal groups to a MAT-file from the Signal Builder window. To export Signal Builder signal data, formatted as Simulink.SimulationData.Dataset, to a MAT-file, open the Signal Builder window and select File > Export Data > To MAT-file. A dialog appears where you can enter a name for the MAT-file to contain the data and the number of the group you want to export. For this example, the file name is slexAutotransRootInportPassingManeuver.mat and the group number is 1 for the Passing Maneuver group.

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 Connect Input button.

Map Signals to Root Inport

The Root Inport Mapper 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 From MAT-File button on the Root Inport Mapper toolbar. When the link dialog appears, 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 saved 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 Update Model. This verifies 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. Click the Scenario Dataset 'PassingManeuver' in the scenario dataset list. To apply the results of the Map action and load the data that was mapped to the input ports from the MAT-file to the base workspace click the Mark for Simulation button. This action also sets the Model Configuration Parameters->Data Import/Export->External Input edit box with the proper comma-separated list of inputs.

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.

Alternative Workflows to Load Mapping Data

After you save the mapping definition to a model, you can automate data loading and 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 similar to:

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

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

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

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

  • Simulates a model after loading each signal group.

Note

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

% 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));
    
    %create a dataset
    ds = Simulink.SimulationData.Dataset();
    ds = ds.addElement( var1, 'var1');
    ds = ds.addElement( var2, 'var2');
    ds = ds.addElement( var3, 'var3');
    
    % Save the data 
    save([fileName '_' num2str(k) '.mat' ],'ds');
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

When you are satisfied with the data and mapping, you can configure your model to load to the MATLAB workspace a MAT-file of the same signal group. Call the load function in a PreLoadFcn callback in the model properties 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 that loads the signal data MAT-file. For example,

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

Related Examples

More About