Main Content

trend

(To be removed) Display graphical trend of OPC data for group

Support for the OPC Data Access (DA) standard will be removed in a future release. Instead use OPC Unified Architecture (UA). See Compatibility Considerations.

Syntax

H = trend(GObj)
H = trend(GObj, 'PropertyName', PropertyValue,...)

Description

H = trend(GObj) displays the newest 100 points of live data for the items defined in the dagroup object 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 H.

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, 'PropertyName', PropertyValue,...) 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.

Property Name

Description

Default

DisplayTime

Defines the number of seconds of history to display in the plot.

100*gObj.UpdateRate

Parent

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 GObj. If the value is a vector, each item's value is displayed in the respective axes object.

Current axes

PlotType

Defines the plot types for each item. Valid plot types are 'line', 'stairs', and 'stem'. The value can be a scalar, or a cell array the same length as the number of items in GObj. If the value is a cell array of character vectors, each item’s plot type is set to the respective plot type in the value array.

'line'

DateTimeFormat

Sets the display format for the x-axis of all axes objects into which data is plotted. DateTimeFormat must be one of the date formats recognized by datetime.

Depends on system locale. See Set Date and Time Display Format.

BufferTime

Defines the number of seconds of history to store for all items. Setting this value to a number greater than the value of DisplayTime allows you to pause the trend (by setting the Subscription property of the group to 'off') and panning the axes in question.

10*DisplayTime

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 shown. Call 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:

  • The DataChangeFcn property is set to update the axes with new data whenever it is received from the OPC server. If there is an existing DataChangeFcn callback, the trend functionality overwrites the callback.

  • The Subscription property is configured to 'on' to receive Data Change events from the OPC server. You can change Subscription to 'off' after calling trend, in which case the trend stops updating until you set Subscription back to 'on' or issue a readasync command.

Examples

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

Version History

Introduced in R2007b

expand all

Version History

Introduced in R2007b

expand all

See Also

Functions