| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → OPC Toolbox |
| Contents | Index |
| Learn more about OPC Toolbox |
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 quality strings 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');
connect(da);
grp = addgroup(da, 'ExOPCREAD');
itm1 = additem(grp, 'Triangle Waves.Real8');
itm2 = additem(grp, 'Saw-Toothed Waves.Int2');
set(grp, 'LoggingMode', 'memory', 'UpdateRate', 0.5, ...
'RecordsToAcquire', 60);
start(grp);
wait(grp);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});
getdata | opcread | opcstruct2array | timeseries
![]() | opcstruct2array | opcsupport | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |