Viewing Signals in Model Reference Instances
This example shows how to use the Simulation Data Inspector to view and analyze signals in referenced models. The Simulation Data Inspector relies on signal logging so this example shows how to configure your model to log signals in referenced models.
Open the Example Models
Run the following command to create and open a working copy of the project files.
The project example copies files to your temporary folder so that you can edit them and use them under local version control.
The Simulink® Project Tool opens and loads the project already under version control.
The project is configured to run some startup tasks.
Setting up Signals to Log in Referenced Models
The first task in setting up a referenced model to view signals using the Simulation Data Inspector is to set up that model for logging. To do that, edit the referenced model and mark the signals for logging. Note that four signals are already set up for logging (marked with the blue wi-fi badge). To log an additional signal:
- Select the raw output signal
- On the Simulink Editor toolbar, click the Simulation Data Inspector drop-down and select Log Selected Signals, as shown below
Once the signals to log have been selected in the referenced model, the next step is to select which signals to actually log from the topmost model in the hierarchy. Selecting the Configure Logging... menu item on the top model's Simulation Data Inspector button activates the Configuration Parameters > Data Import/Export pane.
Click the Configure Signals to Log... button to activate the Simulink Signal Logging Selector dialog.
There are two Logging modes that can be used when logging signals in referenced models. The first is Log all signals as specified in model, which will honor any logging settings that were made in referenced models. If you need to override any of those settings, such as selecting only a subset of logged signals, then you should use the Override signals mode. In this mode, you are given the ability to select a subset of loggable signals and configure their properties, such as decimation and name.
Viewing and Analyzing Logged Signals Using the Simulation Data Inspector
Once logging has been configured for a model hierarchy and all changes to the models have been saved, the model can be simulated. The simulation creates a Dataset object in the base workspace. You can analyze and view the logged data in this object using standard MATLAB tools. In addition, Simulink provides the Simulation Data Inspector, for viewing and analyzing data created from simulations. See the documentation for more details on using the Simulation Data Inspector.
With the Simulation Data Inspector, you can:
- View signal traces for any logged signals
- Visually compare signal values for any logged signals
- Compare signal values collected over multiple simulations
To enable the Simulation Data Inspector, make sure that the Record button on the toolbar of the topmost model is toggled on before starting the simulation. Then after a simulation is done or while using the Simulation Stepper you will see a highlight around the Record button, which indicates that clicking it will open the Data Inspector.
For example, you can use the Simulation Data Inspector to view the output signal of two of the instances of the model LimitedCounter. In the Simulation Data Inspector, you can see that CounterA increases more rapidly than CounterB. This behavior is expected because the Pulse Generator driving this model is running at a faster rate.
You can configure what to display in the inspect table by clicking the gear icon at the right top of the table.
Another useful tool that the Simulation Data Inspector provides is the ability to compare multiple simulation runs. This functionality can help you understand how changes to your model will affect results. For example, you can change the value of the upper limit of the counter models to 8 and simulate the model again to see how that affects output values. To change the value, double click on the block MultiInstanceModelExample/upper and modify the Value parameter to 8.
Now if you compare the results from the first simulation for the output of the CounterA instance of LimitedCounter, you see that the upper limit of this signal has changed from 10 to 8, as expected. Because the tolerances are set to zero, the red octagon next to each signal indicates that the values have changed between runs.