Main Content

Data

R2026b

Access historical data retrieved from OPC UA node

    Description

    An opc.ua.Data object represents historical data retrieved from OPC UA nodes. When you retrieve historical values, OPC UA servers might return a different number of Value, Quality, and Timestamp arrays for each node. This data is packaged into an OPC UA data object, which allows you to process this data for common analysis tasks.

    Creation

    You can construct OPC UA data objects using the readHistory, readAtTime, or readProcessed functions of an OPC UA client.

    Properties

    expand all

    This property is read-only.

    Name of the node, represented as a character vector.

    This property is read-only.

    Timestamp of data read from node, represented as a datetime vector of timestamps. Timestamps represent the time that the source provided the data to the server. The OPC UA server always returns the datetime values in the time zone of the MATLAB® client used to retrieve the data.

    This property is read-only.

    Value of data read from nodes, represented as a vector of data values. The data type of the vector depends on the data type of the node in the OPC UA server.

    This property is read-only.

    Quality of data read from nodes, represented as a cell array of OPC UA qualities. Each quality string indicates the major status and origin of the data value, such as 'Good (Raw)' or 'Uncertain (Interpolated)'.

    Object Functions

    expand all

    summaryDisplay summary of OPC UA data object
    stairsPlot OPC UA data in stairstep graph
    plot Plot OPC UA data in line graph
    tableConvert OPC UA data object to a table
    tsintersectIntersection of timestamps in OPC UA data object
    tsunionUnion of timestamps in OPC UA data object
    arrayHasSameTimeStampVerify if all elements in OPC UA data object have same timestamp
    appendCombine OPC UA data objects
    resampleResample OPC UA data object to have defined timestamps
    filterByQualityFilter OPC UA data by quality characteristics
    getIndexFromNameReturn indices of OPC data matching specified names
    singleConvert OPC UA data object array to single matrix
    doubleConvert OPC UA data object array to double matrix
    int8Convert OPC UA data object array to int8 matrix
    int16Convert OPC UA data object array to int16 matrix
    int32Convert OPC UA data object array to int32 matrix
    int64Convert OPC UA data object array to int64 matrix
    uint8Convert OPC UA data object array to uint8 matrix
    uint16Convert OPC UA data object array to uint16 matrix
    uint32Convert OPC UA data object array to uint32 matrix
    uint64Convert OPC UA data object array to uint64 matrix
    logicalConvert OPC UA data object array to logical matrix

    Examples

    collapse all

    Create an OPC UA client and connect it to the server.

    uaClnt = opcua("localhost",62550);
    connect(uaClnt);

    Construct a node object using index and identifier values.

    uaNode = opcuanode(3,1005,uaClnt);

    Retrieve data for the current day.

    dataObj = readHistory(uaClnt,uaNode,datetime('today'),datetime('now'));

    The retrieved data is stored in a Data object. Summarize and plot the data.

    summary(dataObj);
    1-by-1 OPC UA Data object:
    
          Name          Value           Start Timestamp       End Timestamp                Quality           
        --------  ------------------  -------------------  -------------------  -----------------------------
        Sinusoid  1000 double values  2026-03-27 00:00:01  2026-03-27 00:16:40  1 unique quality [Good (Raw)]
    plot(dataObj);

    Plot of Sinusoid node data

    Load the sample data file and examine the properties of the first element.

    load opcSampleUaData;
    nodeName = uaDataSample(1).Name
    nodeName =
    
        'Counter'
    nodeValues = uaDataSample(1).Value(1:5)
    nodeValues =
    
      5×1 int32 column vector
    
       0
       1
       2
       3
       4
    nodeTimestamps = uaDataSample(1).Timestamp(1:5)
    nodeTimestamps = 
    
      5×1 datetime array
    
       02-May-2026 11:33:09
       02-May-2026 11:33:10
       02-May-2026 11:33:11
       02-May-2026 11:33:12
       02-May-2026 11:33:13
    nodeQuality = uaDataSample(1).Quality(1:5)
    nodeQuality =
    
      5×1 cell array
    
        {'Good (Raw)'}
        {'Good (Raw)'}
        {'Good (Raw)'}
        {'Good (Raw)'}
        {'Good (Raw)'}

    Version History

    Introduced in R2015b