MATLAB Examples

# Create a Run and View the Data

This example shows how to create a run, add data to it, and then view the data in the Simulation Data Inspector.

## Create Data for the Run

This example creates timeseries objects for a sine and a cosine. To visualize your data, the Simulation Data Inspector requires at least a time vector that corresponds with your data.

```% Generate timeseries data time = linspace(0, 20, 100); 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'; ```

To give the Simulation Data Inspector access to your data, use the create method and create a run. This example modifies some of the run's properties to help identify the data. You can easily view run and signal properties with the Simulation Data Inspector.

```% Create a run run = Simulink.sdi.Run.create; run.Name = 'Sinusoids'; run.Description = 'Sine and cosine signals with different frequencies'; % Add timeseries data to run run.add('vars', sine_ts, cos_ts); ```

```% Get signal, modify its properties, and change Checked property to true sine_sig = run.getSignalByIndex(1); sine_sig.LineColor = [0 0 1]; sine_sig.LineDashed = '-.'; sine_sig.Checked = true; % Add another subplot for the cosine signal Simulink.sdi.setSubPlotLayout(2, 1); % Plot the cosine signal and customize its appearance cos_sig = run.getSignalByIndex(2); cos_sig.LineColor = [0 1 0]; cos_sig.plotOnSubPlot(2, 1, true); % View the signal in the Simulation Data Inspector Simulink.sdi.view ```
```Simulink.sdi.close('sinusoids.mat') ```