This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Convert OPC data from structure to time series format


TS = opcstruct2timeseries(S)


TS = opcstruct2timeseries(S) converts the OPC data structure S into a cell array of time series objects. S must be a structure in the format that the getdata and opcread functions return. S must contain the fields LocalEventTime and Items. The Items field of S must contain the fields ItemID, Value, Quality, and TimeStamp.

The cell array TS contains as many time series objects as there are unique item IDs in the data structure, with the name of each time series object indicating the item ID. The time series object contains the quality, although this value is offset by 128 from the quality value that the OPC server returns. However, the qualities are the same. Because each logged record might not contain information for every item, the time series objects have only as many data points as there are records containing information about that particular item ID.


Configure and start a logging task for 30 seconds of data:

da = opcda('localhost', 'Matrikon.OPC.Simulation');
grp = addgroup(da, 'ExOPCREAD');
itm1 = additem(grp, 'Triangle Waves.Real8');
itm2 = additem(grp, 'Saw-Toothed Waves.Int2');
grp.LoggingMode = 'memory';
grp.UpdateRate = 0.5;
grp.RecordsToAcquire = 60;

Retrieve the records into a structure:

s = getdata(grp);

Convert the structure into time series objects and plot each separately:

ts = opcstruct2timeseries(s);
subplot(2,1,1); plot(ts{1});
subplot(2,1,2); plot(ts{2});

See Also



Introduced in R2007b