Simulink.sdi.createRun

Create a run in the Simulation Data Inspector

Description

example

runID = Simulink.sdi.createRun creates an empty, unnamed run in the Simulation Data Inspector repository and returns the run ID. You can use Simulink.sdi.getRun to get a Simulink.sdi.Run object for the run, which allows you to add metadata and signals to the run.

example

runID = Simulink.sdi.createRun(runName) creates an empty run named runName.

example

runID = Simulink.sdi.createRun(var) creates a run named var containing the data in the workspace variable var.

example

runID = Simulink.sdi.createRun(runName,'vars',var,var2,...,varn) creates a run named runName containing data from one or more variables in the base workspace. The signals in the run take their names from the variable names.

example

runID = Simulink.sdi.createRun(runName,'namevalue',sourceNames,sigValues) creates a run named runName with the data in the cell array sigValues. The cell array of sourceNames specifies names to use as the source for the sigValues data.

example

runID = Simulink.sdi.createRun(runName,'file',filename) creates a run with data from the MAT, CSV, MDF, or Microsoft® Excel® file specified by filename.

[runID,runIndex] = Simulink.sdi.createRun(___) returns the run ID and run index for the run created in the Simulation Data Inspector repository.

[runID,runIndex,signalIDs] = Simulink.sdi.createRun(___) returns the run ID, run index within the Simulation Data Inspector, and the signal IDs for the signals in the run.

Examples

collapse all

This example shows several ways to create a run in the Simulation Data Inspector for your data. You can create a run from simulation outputs, workspace data, and from a file.

Create Data

You can create Simulation Data Inspector runs from workspace data or from a file. The namevalue syntax for Simulink.sdi.createRun can be useful for hierarchical data. Create example data to use in each scenario.

% Create timeseries workspace data
time = linspace(0,20,101);

sine_vals = sin(2*pi/5*time);
sine_ts = timeseries(sine_vals,time);
sine_ts.Name = 'Sine, T=5';

cos_vals = cos(2*pi/8*time);
cos_ts = timeseries(cos_vals,time);
cos_ts.Name = 'Cosine, T=8';

% Create Dataset workspace data
sinusoids_ds = Simulink.SimulationData.Dataset;
sinusoids_ds = sinusoids_ds.add(cos_ts);
sinusoids_ds = sinusoids_ds.add(sine_ts);

doubSine = 2*sine_ts;
doubCos = 2*cos_ts;

doubSinusoids_ds = Simulink.SimulationData.Dataset;
doubSinusoids_ds = doubSinusoids_ds.add(doubSine);
doubSinusoids_ds = doubSinusoids_ds.add(doubCos);

% Save workspace data to a MAT-file
save sinusoids.mat sine_ts cos_ts

Create a Run with a Run Object

You can create a run object using the Simulink.sdi.Run object's create method and then add data to the run using the add method. The add method supports all loading and logging data formats.

% Create a run
sinusoidsRun = Simulink.sdi.Run.create;
sinusoidsRun.Name = 'Sinusoids';
sinusoidsRun.Description = 'Sine and cosine signals of different frequencies';

% Add timeseries data to run
sinusoidsRun.add('vars',sine_ts,cos_ts);

Create a Run for a Variable

When you have only one signal of interest that you want to inspect and compare in the Simulation Data Inspector you can use a simple syntax to create the run. The run takes the same name as the variable.

runID = Simulink.sdi.createRun(sine_ts);

Create a Named Empty Run

With this syntax, you can create an empty run and specify its name. Then, you can use the returned runID to add data to the run.

runID = Simulink.sdi.createRun('My Waves');
signalID = Simulink.sdi.addToRun(runID,'vars',cos_ts);

Create a Run from Multiple Workspace Variables

When your signals of interest are in multiple variables in your workspace, use the 'vars' syntax. You can also use this syntax to provide a custom name for a run created from a single variable.

runID = Simulink.sdi.createRun(' My Sinusoids','vars',sine_ts,cos_ts);

Create a Run and Specify the Source for the Data

Providing a name for the source of the run data can be helpful, particularly with hierarchical data. Use the 'namevalue' syntax to specify data source names.

runID = Simulink.sdi.createRun('Waves','namevalue',{'Sinusoids',...
    'BigSinusoids'},{sinusoids_ds,doubSinusoids_ds});

Create a Run from Data in a File

You can create a run in the Simulation Data Inspector directly from a file of data using the 'file' syntax.

runID = Simulink.sdi.createRun('Wave Data','file','sinusoids.mat');

View Runs in the Simulation Data Inspector

Look at the runs in the Inspect pane to see the results from each run creation method. You can select a run or a signal to view its metadata.

Simulink.sdi.view

This example shows how to access signal data when you create a run in the Simulation Data Inspector.

Generate Data for Run

For this example, create timeseries data for sine and cosine signals.

% Create timeseries workspace data
time = linspace(0, 20, 101);

sine_vals = sin(2*pi/5*time);
sine_ts = timeseries(sine_vals,time);
sine_ts.Name = 'Sine, T=5';

cos_vals = cos(2*pi/8*time);
cos_ts = timeseries(cos_vals,time);
cos_ts.Name = 'Cosine, T=8';

Create a Run and Return Signal IDs

You can use the Simulink.sdi.createRun syntax with multiple return arguments to get the signal IDs more directly instead of accessing the signal IDs through a Simulink.sdi.Run object.

[runID,runIndex,sigIDs] = Simulink.sdi.createRun('Sinusoids','vars',...
    sine_ts,cos_ts);

cosID = sigIDs(2);
cosSig = Simulink.sdi.getSignal(cosID);

Modify Signal Properties and View in the Simulation Data Inspector

You can use the Simulink.sdi.Signal object to view and modify signal properties and to plot signals in the Simulation Data Inspector.

cosSig.Checked = true;
cosSig.AbsTol = 0.05;
Simulink.sdi.view
cosSig.Name

Input Arguments

collapse all

Name for the run in the Simulation Data Inspector.

Example: 'Baseline Simulation'

Variable in the base workspace containing the data you want to create a run for in the Simulation Data Inspector. The Simulation Data Inspector requires an associated time vector for your data. Simulink.sdi.createRun supports all loading and logging data formats, including timeseries and Simulink.SimulationData.Dataset.

Provide one var argument when var is the only argument and one or more var arguments when you specify 'vars' for the second argument.

Example: myData

Cell array of character vectors in which each element is the name of the source for data in the run. Provide a sigNames input when you specify 'namevalue' for the second argument.

Example: {'sig1','sig2'}

Cell array of variables containing signal data for the run. Provide a sigValues input when you specify 'namevalue' for the second argument.

Example: {var1,var2}

File name of the file containing your run data. Provide a filename input when you specify 'file' for the second argument. You can create a run from a MAT, CSV, or Microsoft Excel file. You can also create a run from an MDF-file with an mdf, mf4, mf3, data, or dat file extension.

Example: 'simulation.mat'

Output Arguments

collapse all

Run identifier for the new run.

Index of the new run in the Simulation Data Inspector repository.

Vector containing the signal IDs for the signals in the run.

Introduced in R2011b