Documentation

Simulink.sdi.setSubPlotLayout

Set subplot layout in the Simulation Data Inspector

Syntax

Simulink.sdi.setSubPlotLayout(r,c)

Description

example

Simulink.sdi.setSubPlotLayout(r,c) sets the grid layout of plots in the Simulation Data Inspector using the specified number of rows, r, and columns, c.

Examples

collapse all

% Change subplot layout to 4 rows and 2 columns
Simulink.sdi.setSubPlotLayout(4,2);

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';

Create a Simulation Data Inspector Run and Add Your Data

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);

Plot Your Data Using the Simulink.sdi.Signal Object

The getSignalByIndex method returns a Simulink.sdi.Signal object that can be used to plot the signal in the Simulation Data Inspector. You can also programmatically control aspects of the plot's appearance, such as the color and style of the line representing the signal. This example customizes the subplot layout and signal characteristics.

% 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

Close the Simulation Data Inspector and Save Your Data

Simulink.sdi.close('sinusoids.mat')

Input Arguments

collapse all

Number of rows in the subplot grid layout, specified as a whole number between 1 and 8, inclusive.

Example: 2

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char

Number of columns in the subplot grid layout, specified as a whole number between 1 and 8, inclusive.

Example: 2

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char

Introduced in R2016a

Was this topic helpful?