Display graphical trend of OPC data for group
H = trend(GObj)
H = trend(GObj, '
H = trend(GObj) displays the
newest 100 points of live data for the items defined in the
GObj in the current axes.
GObj must be an active group containing one or more items.
The handles to the created Handle Graphics®
objects are returned in
All the items are displayed in the same axes, with no scaling. New data is displayed on the far right of the axes, and oldest data is displayed on the left. If no old data exists (such as at the beginning of a plot), the axes are empty. The Handle Graphics objects (including the axis limits) are updated with new data whenever the group object receives a Data Change event from the OPC server.
H = trend(GObj, '
allows you to pass additional property/value pairs to specify additional properties
of the created plots. Special property/value pairs are listed in the following
table. If any property is not in this list, that property/value pair is passed on to
the created Handle Graphics objects.
Defines the number of seconds of history to display in the plot.
Defines the parent axes objects in which to display the
trends. The value can be a scalar, or a vector the same length
as the number of items in
Defines the plot types for each item. Valid plot types are
Sets the display format for the x-axis
of all axes objects into which data is plotted.
Defines the number of seconds of history to store for all
items. Setting this value to a number greater than the value of
You can fix the axes y-limits to
a particular value by using the
YLim property of the axes
containing your visualized data. For example, to set the limits of the
y-axis to the instrument range reported by the OPC server,
use the following code:
props = serveritemprops(da,itmName,102:103); currentAxes = gca; currentAxes.YLim = [props.PropValue];
If you add items to a group that currently has an active trend, the item is not
trend again to include that item in the trend view.
(If you set the hold state of the axes to
'on', when you call
trend, existing trend objects are reused, without
destroying their current view.)
If you delete an item from a group that currently has an active trend, the trend display shows no data for that item, and the item’s trend eventually disappears off the graph.
This function overwrites the following properties of the group object:
DataChangeFcn property is set
to update the axes with new data whenever it is received from the OPC
server. If there is an existing
the trend functionality overwrites the callback.
Subscription property is
'on' to receive Data Change events from the
OPC server. You can change
'off' after calling
which case the trend stops updating until you set
Subscription back to
Configure a group with two items:
da = opcda('localhost','Matrikon.OPC.Simulation'); connect(da); grp = addgroup(da,'ExOPCTREND'); itm1 = additem(grp,'Triangle Waves.Real8'); itm2 = additem(grp,'Saw-Toothed Waves.Int2');
Create a trend showing the last two minutes of data in two separate axes:
ax1 = subplot(2,1,1); ax2 = subplot(2,1,2); trend(grp,'DisplayTime',120,'Parent',[ax1,ax2]);