Use the Root Inport Mapping tool to import, visualize, and map signal and bus data to root-level inports.
Root-level inport mapping imports signal data meets most modeling requirements and maintains model flexibility.
Test your model with signals from the workspace and use your model as a referenced model in a larger context without any modification. Test signals in your model without disconnecting the inports and connecting sources to them.
Use the Root Inport Mapping tool to update the Input parameter based on the signal data that you import and map to root-level inports.
Visually inspect signal data without loading all the signal data into MATLAB® memory.
To use the Root Inport Mapping tool:
Create signal data in the MATLAB workspace.
For a Simulink® model, import the data from the workspace. You can visualize the data you import.
Map the data to root-level inports.
Simulate the model.
Save the Root Inport Mapping scenario.
This model has three root-level Inport blocks. Two of the Inport blocks output scalar signals and the other Inport block outputs bus data. Open the model.
This example shows how you can use the Root Inport Mapping tool to test the model with data. This approach can be useful for performing standalone testing of a model that another model references.
You can define the signal data as MATLAB
Define the time values for the signal data.
sampleTime = 0.01; endTime = 10; numberOfSamples = endTime * 1/sampleTime +1; timeVector = (0:numberOfSamples) * sampleTime;
Create the data for the two scalar signals. Naming the data variable to match the name of the corresponding signal makes it easier to map data to signals.
signal_1 = timeseries(sin(timeVector)*10,timeVector); signal_2 = timeseries(rand(size(timeVector)),timeVector);
Create the signals for the bus.
busSignal.busElement_1 = timeseries(cos(timeVector)*2,timeVector); busSignal.busElement_2 = timeseries(randn(size(timeVector)),timeVector);
Create the bus object for the output data type of
Bus_1 Inport block. You can create the bus
object from the bus signal that you defined. Use a bus object for
bus signals that cross model reference boundaries.
busInfo = Simulink.Bus.createObject(busSignal);
Import the signal data that you created from the workspace into the Root Inport Mapping tool. Then you can use the tool to visualize the imported data.
Open the Root Inport Mapping tool. Open the Block Parameters dialog box for one of the Inport blocks in the model and click Connect Input.
In the Root Inport Mapping tool, select the From Workspace button.
In the Import dialog box, specify a MAT-file to save signals to. For this example, use the default.
Click the Name check box to clear
the data variables. Then click the check boxes for the
Although in this example you select all the signals, you can select a subset of signals.
Leave the Convert signals into a scenario dataset and save to MAT-file check box enabled and click OK.
You can visualize signals. In the Root Inport Mapping dialog box toolbar, click Preview Signals.
The Preview tab appears. You can select
signals to plot. For example, to see a plot of
in the Navigation pane, expand the scenario data set (in this example,
the top node,
untitled) and then expand the
Select the check box for
signal_1(1,1,:) to plot
Close the Preview tab by clicking the Close Signal Preview button.
After you import the data, you map which data to use for specific Inport blocks.
Select the map mode, which specifies the criteria the mapping uses. In the toolbar, select the Signal Name radio button.
The signals in this model have names, so mapping based on signal names makes it very clear which data is going to an Inport block.
You can specify options for the mapping. In the toolbar, select Options. Select Compile, which updates the model after you do the mapping. Compiling the model verifies that signal dimensions and data types match between the data and the Inport blocks.
Map the data. In the Navigation pane, select the scenario data set. In the toolbar, click Map to Model. The dialog box shows the mapped data.
If you want to reuse the mapping and data that you have set
up, you can save it as a scenario. In the Root Inport Mapping tool,
click Save > Save
As and save the scenario as an
In the Navigation pane, select the scenario data set.
In the toolbar, click Mark for Simulation.
The model is now set up to simulate using the workspace signal data that you mapped to root—level Inport blocks.
Simulate the model.
This model includes a Dashboard block that shows the data used
during simulation for
signal_1. The plot matches
the plot you did when you visualized the data as part of the data