Main Content

Read Historical Data at Specific Times

The readAtTime function reads the values for a list of item IDs at specific times. This is useful if your analysis routine requires regularly sampled data and you can accept the interpolation scheme used by your server. If no value exists on the server at the exact timestamp requested, the value is interpolated from the surrounding data values.

For example, if you wanted the values of two items at this current moment and their values at the same time yesterday, you could use the following code:

itemList = {'Random.Int1', 'Random.Boolean'}
timeStamps = [now; now-1];	
dataObject = readAtTime(hdaClient, itemList, timeStamps)

Additionally, you can request that the data be returned as a supported MATLAB® data type. See Native MATLAB Data Types from Read Operations.

The same example could be called, but with a MATLAB data type specified as a fourth parameter. This function call returns all the data values as 8-bit signed integers:

dataObject = readAtTime(HdaClient, ItemList, TimeStamps, 'int8')

You can now use this object as required, or display it as described in Display Data Objects.