simscape.logging.plot

Package: simscape.logging

Plot logged simulation data for node or series

Syntax

h = simscape.logging.plot(obj,Name,Value)

Description

h = simscape.logging.plot(obj,Name,Value) plots the simulation series values along the y-axis, with time along the x-axis. obj is an object (or a homogeneous cell array of objects) of class simscape.logging.Node or simscape.logging.Series. If obj is a node, plots all nonempty series associated with the specified node and its children. You can filter data being plotted by using the name-value pair arguments. Depending on the type of obj, h is a structure (for a node) or a cell array (for a series) of handles to the resulting figures.

Input Arguments

obj

An object of class simscape.logging.Node or simscape.logging.Series. Can also be a homogeneous cell array of objects of either of these two classes. obj must include a full identifier path to the node or series, starting with the workspace log variable name.

The following table describes the resulting plots based on the type of the obj argument:

Scalar series object

Plots the simulation series values along the y-axis, with time along the x-axis.

Nonscalar series object

Plots each dimension of the series values on a different axis in the same figure window.

Cell array of series objects

Plots all series objects with commensurate units on the same axis (superimposed), and each dimension for a nonscalar series on a different axis in the same figure window.

The input arguments are binned based on commensurate units. For each bin, all series objects with the same dimension as the first series object in that bin are plotted and others are ignored.

Node object

Plots all nonempty series associated with the node and its children (up to the level defined by the depth). If a node has multiple children, at level 1, that are simulation variable nodes, these children are plotted in the same figure window but on a different axis. Descendants at other levels are plotted in different figure windows. All dimensions of a nonscalar series are plotted on the same axis.

Cell array of node objects

Plots commensurate series superimposed on the same axis.

Intended for use to compare simulation data from different runs. All entries of the cell array are required to be equivalent to each other, meaning that the node objects must have same hierarchy, and the series objects for each node must have the same dimensions and commensurate units.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'depth'

Plot data for children at n levels, where n is a nonnegative integer, for example:

0No children; plot the nonempty series of the specified node only.
1Plot the nonempty series of the specified node and its children.
2Plot the nonempty series of the specified node, its children, and their children.

This argument is ignored if obj is a series.

Default: Plots all descendants of the node object that have nonempty series.

'names'

Adds the plot legend. The number of elements must be same as the number of elements of obj.

Default: No legend.

'time'

Plot data in the specified time range only. Provide a 1x2 vector [start_time end_time] to specify the time range. [] plots all data.

Default: Plots all data.

'units'

Plot the series values in the specified units. This argument filters the data to plot only nodes and series that are commensurate with the specified unit. The value can be a single unit or a cell array of units. Unit names must appear inside single quotes ('').

Default: Plots all data.

Output Arguments

h

A structure or a cell array of handles to the resulting plot figure windows, depending on the type of obj. If obj is a series, h is a cell array. If obj is a node, h is a structure with the same hierarchy as the object being plotted. For example, if a specific child is not plotted then that field in the output structure is empty.

Examples

Plot all positions and velocities (series that are commensurate with units of mm and mm/s) in those units, respectively, for the top-level model node (with the default workspace variable name, simlog), its children and their children, within the time range between 1 and 3 seconds:

h = simscape.logging.plot(simlog, 'units', {'mm', 'mm/s'}, 'time', [1 3], 'depth', 2);

Compare data from two simulation runs. Supposing you use the workspace variable name simlog1 to log the data from the first run, and the workspace variable name simlog2 to log the data from the second run, the following command plots deformation of the Translational Spring block TS from both runs on the same axis, with the corresponding legend:

simscape.logging.plot({simlog1.TS.x simlog2.TS.x}, 'names', {'Run1' 'Run2'});

Was this topic helpful?