You can programmatically import data into the Simulation Data Inspector by creating a run from data in the base workspace or a file. This example creates data in the workspace and then illustrates several methods of creating a Simulation Data Inspector run containing the data.
Create Data
Create data in the workspace. The Simulation Data Inspector supports time series data in many formats. This example creates data using the timeseries
and Simulink.SimulationData.Dataset
formats and saves the data in a MAT-file.
Create a sine signal and a cosine signal. Store the data for each signal in a timeseries
object with a descriptive name.
You can use the Dataset
format to group related signal data together in a single object. The Dataset
format is the default format for logged data and is supported for loading simulation input data. Create a Dataset
object that contains the sinusoid timeseries
data.
Scale each signal by a factor of 2
and create a Dataset
object to contain the signal data for the results.
Finally, save the timeseries
data to a MAT-file.
Open the Simulation Data Inspector
To view the runs you create in each section, open the Simulation Data Inspector by entering Simulink.sdi.view
in the MATLAB™ Command Window.
Create a Run Using a Simulink.sdi.Run
Object
You can import your data into a run in the Simulation Data Inspector by creating an empty run and then adding data to the run from the workspace or a file. Depending on your task, you can use the Simulink.sdi.Run.create
function or the Simulink.sdi.createRun
function to create the empty run. The Simulink.sdi.Run.create
function returns the Simulink.sdi.Run
object for the new run, and the Simulink.sdi.createRun
function returns the run ID for the new run.
This example creates an empty run using the Simulink.sdi.Run.create
function, gives the run a meaningful name and description, and then adds the sine and cosine timeseries
data using the add
function.
This example uses the Simulink.sdi.createRun
function to create a new run in the Simulation Data Inspector called My Waves
and then uses the Simulink.sdi.addToRun
function to add the sine and cosine timeseries
data to the run.
Create a Run from a Workspace Variable
You can create a run from a single variable in the workspace. After creating the run, you can add additional data, or you can create another run to contain your other data. The variable you use to create the run can be a timeseries
object with data that corresponds to only one signal, or it can be a Dataset
object that contains several signals.
When you use this syntax to create a run from a single workspace variable, the run takes the same name as the object used to create it.
The Simulink.sdi.createRun
function returns the run ID for the run it creates. You can use the Simulink.sdi.getRun
function to access the Run
object for the run.
Create a Run from Multiple Workspace Variables
When your data exists in multiple variables in your workspace, you can use the Simulink.sdi.createRun
function with the vars
option to import the data from multiple variables into a single run in the Simulation Data Inspector. You can also use this syntax to create a run for a single variable that uses a name you specify.
This example creates a run called My Sinusoids
that contains data for the sine and cosine timeseries
objects.
Create a Run and Specify Source Names
You can use the namevalue
option of the Simulink.sdi.createRun
function to create a run and specify names for the signals in the run. This syntax can be particularly helpful when you import individual leaf signals from hierarchical data.
This example creates a run containing the data for both the Dataset
objects. Each Dataset
object contains data for more than one signal, so the imported run data has hierarchy. The name-value syntax in this example specifies a name for the hierarchical node that corresponds to each Dataset
object.
Create a Run from Data in a File
You can also use the Simulink.sdi.createRun
function to import data into the Simulation Data Inspector from a file. Use the file
option to import the data in the simusoids.mat
file.