Simulink.sdi.addToRun

Add one or more signals to existing run

Description

example

sigIDs = Simulink.sdi.addToRun(runID,'vars',var,var2,...,varn) adds the data in the variables var,var2,...,varn to the run corresponding to the runID and returns the signal IDs for the signals added to the run.

example

sigIDs = Simulink.sdi.addToRun(runID,'namevalue',sourceNames,dataValues) adds the data in the cell array dataValues to the run corresponding to the runID and returns the signal IDs for the signals added to the run. The sourceNames argument specifies names to use for the source of the data in dataValues in the signal metadata.

Examples

collapse all

This example shows how to use Simulink.sdi.addToRun to add workspace data to a run in the Simulation Data Inspector.

Generate Workspace Data

Generate workspace data to add to a simulation run in place of measured data, input data, or any other data that you want to associate with the simulation.

time = linspace(0, 60, 201);
cos_vals = 2*cos(2*pi/6.8*time);
cos_ts = timeseries(cos_vals, time);
cos_ts.Name = 'cosine';

Simulate Model

Simulate the slexAircraftExample model to create a run containing the simulation outputs.

load_system('slexAircraftExample');
sim('slexAircraftExample','SaveFormat','Dataset');

Add Workspace Data to Simulation Run

Add the workspace data to the run. Then, view the results in the Simulation Data Inspector.

% Get run ID
count = Simulink.sdi.getRunCount;
runID = Simulink.sdi.getRunIDByIndex(count);

% Add data to run
sigIDs = Simulink.sdi.addToRun(runID,'vars',cos_ts);

Simulink.sdi.view

The model slexAircraftExample is configured to log outputs, states, and time data. The output data automatically logs to the Simulation Data Inspector as well as the base workspace, but the states data does not. To bring the states data into the Simulation Data Inspector, you can record the data, or you can add it to the run created by simulating the model. This example shows how to add logged states data to a Simulation Data Inspector run programmatically.

Simulate the Model and Get States Data

Simulate the model using the sim function with 'ReturnWorkspaceOutputs' set to 'on'. Select the states data, xout, from the simulation outputs.

load_system('slexAircraftExample')

simOut = sim('slexAircraftExample','ReturnWorkspaceOutputs','on',...
    'SaveFormat','Dataset');

% Get states data from simulation output
states = simOut.xout;

Get the Run ID

Because the outputs data automatically logs to the Simulation Data Inspector, a run is created upon simulating slexAircraftExample. Get the run ID for the run using the Simulation Data Inspector programmatic interface.

runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

Add States Data to the Run

Add the states data to the run with the output data.

sigIDs = Simulink.sdi.addToRun(runID,'namevalue',{'States'},{states});

Input Arguments

collapse all

Run ID for the signal you want to add data to. The Simulation Data Inspector assigns a unique run ID when it creates a run. You can get the run ID for your run using Simulink.sdi.getAllRunIDs and Simulink.sdi.getRunIDByIndex.

Workspace data to add to the run. Simulink.sdi.addToRun supports all loading and logging data formats, including timeseries and Simulink.SimulationData.Dataset. Provide one or more var inputs when you specify 'vars' as the second argument.

Example: myData

Names to use as the source of the data in the metadata for the added signals. Provide a sourceNames input when you specify 'namevalue' as the second argument.

Example: {'speed','position'}

Cell array of data to add to the run. Provide a dataValues input when you specify 'namevalue' as the second argument.

Example: {sig1,sig2}

Output Arguments

collapse all

Matrix of signal IDs for signals added to the run.

Introduced in R2011b