主要内容

可视化和预处理OPC UA数据

此示例显示了如何使用OPC UA数据对象。

当从OPC UA服务器读取历史数据时,创建OPC UA Data对象。OPC UA数据对象允许您存储、可视化和操作历史数据,然后将数据转换为内置数据类型,以便在MATLAB中进行进一步处理。

有关生成OPC UA数据对象的更多信息,请参阅示例读取历史OPC UA服务器数据

加载示例OPC UA数据集

将示例数据加载到工作区中。

负载demoUA_SampleData

显示OPC UA数据对象

检查工作区以查看加载了哪些变量。

Name Size Bytes Class Attributes dataSample 1x3 5926 opc.ua.Data . Name Size Bytes Class Attributes dataSample 1x3 5926 opc.ua.Data . Name Size Bytes

显示示例数据的摘要。

总结(dataSample)
1 × 3 OPC UA数据对象:名字开始时间结束时间戳值质量  ------ ---------------- ----------------------- ----------------------- ------------------ 双9双值2015-04-22 09:00:10.000 2015-04-22 09:01:30.000 3独特品质浮动12单值2015-04-22 09:00:02.000 2015-04-22 09:01:30.000 3独特品质Int32 12 Int32值3种独特的品质

数据对象包含三个数据集。第一个元素包含9个值,第二个和第三个有12个值。

漂浮INT32.数据集具有相同的时间戳。

Arrayhassametimestamp(DataMple(2:3))
ans = 1

显示漂浮INT32.数据集在一起。因为所有元素都有相同的时间戳,所以可以显示一个值表

数据征(2:3)
ANS = 1-BY-2 OPC UA数据对象数组:时间戳浮点INT32 ----------------------------  --------------------------------------------  2015-04-22 09:00:02.000 10.000000 [Good(RAW)] 10 [Good(RAW)] 2015-04-22 09:00:25.000 20.000000 [良好(原始)] 20 [良好(原始)]2015-04-22 09:00:28.000000 [良好(原始)] 25 [良好(原始)] 2015-04-22 09:00:40.000 30:0000 [Good(RAW)] 30 [Good(RAW)] 2015-04-22 09:00:42.000 0.000000 [坏(RAW)] 0 [坏(RAW)] 2015-04-22 09:00:48.000 4.000000 [良好(原始)] 40 [良好(原始)] 2015-04-22 09:00:52.000 50.000000 [良好(RAW)] 50 [GOOD(RAW)] 2015-04-22 09:01:12.000 60.000000 [GOOD(RAW)] 60 [GOOD(RAW)] 2015-04-22 09:01:17.000 70.000000 [不确定(RAW)] 70 [不确定(RAW)] 2015-04-22 09:01:23.000 70.000000 [GOOD(RAW)] 70 [GOOD(RAW)] 2015-04-22 09:01:26.000 80.000000 [良好(原始)] 80 [良好(原始)] 2015-04-22 09:01:30.000 90.000000 [良好(原始)] 90 [良好(原始)]

更改日期显示格式

使用当前日期显示格式使用opc.getDateDisplayFormat

origFormat = opc.getDateDisplayFormat;

将显示格式更改为标准的美国日期格式,并再次显示该值。

opc.setDateDisplayFormat ('mm / dd / yyyy hh:mm');数据征(2:3)
ans = 1 × 2 OPC UA数据对象数组:时间戳Int32浮动  ------------------- ------------------------------- -------------------------------- 04/22/2015早上9点10.000000[好(生)]10[好(生)]04/22/2015早上9点20.000000[好(生)]20[好(生)]04/22/2015早上9点25.000000[好(生)]25[好(生)]04/22/2015早上9点30.000000[好(生)]30 04/22/2015好(生)早上9点0.000000[坏(生)]0[坏(生)]04/22/2015早上9点4.000000[好(生)]40[好(生)]04/22/2015早上9点50.000000[好(生)]50[好(生)]04/22/2015 9:01是60.000000[好(生)]60[好(生)]04/22/2015 9:01是70.000000(不确定(生))70(不确定(生)]04/22/2015 9:01是70.000000[好(生)]70[好(生)04/22/2015 9:01 AM 80.000000 [Good (Raw)] 80 [Good (Raw)]

将显示格式重置为默认值。

opc.setDateDisplayFormat (“默认”
ans = yyyy-mm-dd HH:MM:SS。FFF

将显示格式重置为原始值。

opc.setdatedisplayformat(Origformat);

可视化OPC UA数据

可视化OPC UA数据使用情节楼梯数据对象上的方法。

AXH1 =子图(2,1,1);绘图(数据群);标题(“样本数据图”);AXH2 =子图(2,1,2);楼梯(DataMple);标题(“样本数据的阶梯图”);传奇(“位置”'西北'

重新取样OPC UA数据

数据中的数据dataSample设置有不同的时间戳。

arrayHasSameTimestamp (dataSample)
ans = 0.

尝试将数据转换为双数组。转换将失败。

试一试瓦尔斯=双(dataSample);exc disp (exc.message)结束
转换为双重失败。OPC数据对象的所有元素必须具有相同的时间戳。考虑使用数据对象上的“tsunion”,“tsintersect”或“重组”。

数据时间戳的交集会产生一个更小的数据集,其中包含来自所有元素的公共时间戳。

dataIntersect = tsintersect (dataSample)
dataIntersect = 1 × 3 OPC UA数据对象数组:时间戳双浮子Int32  ----------------------- -------------------------- -------------------------- --------------------------- 2015-04-22 09:00:40.000 40.000000[坏(生)]30.000000[好(生)]30[好(生)]2015-04-22 09:01:30.000 90.000000[好(生)]90.000000[好(生)]90[好(生)

将数据对象转换为双数组。

Vals = Double(Dataintersect)
瓦尔斯= 40 30 30 90 90 90

使用Tsunion在数据对象中返回时间序列的结合。使用提供的方法(或如果没有提供方法),使用所提供的方法(或线性插值)内插。对于这些新值,质量被设置为“插值”。

dataunion = tsunion(DataSample)
dataUnion = 1 × 3 OPC UA时间戳双浮子Int32  ----------------------- -------------------------------------------------- ----------------------------------- ------------------------------------ 2015-04-22 03:00:02.000 2.000000[不确定:弱智者(插值)]10.000000[好(生)]10[好(生)]2015-04-22 03:00:10.000 10.000000(好(生))13.478261(好[Good (Interpolated)] 2015-04-22 03:00:20.000 20.000000 20.000000 [Good (Interpolated)] 17.826086 [Good (Interpolated)] 2015-04-22 03:00:25.000 25.000000 [Good (Interpolated)] 20000000 [Good (Raw)03:00:30.000 3 .000000 [Good (Raw)] 25.833334 [Good (Interpolated)] 26 [Good (Interpolated)] 2015-04-22 03:00:40.000 4.000000 [Bad (Raw)] 3 .000000 [Good (Raw)] 30 [Good (Raw)] 2015-04-22 03:00:42.000 4000000 [Good (Interpolated)] 0 [Bad (Raw)] 2015-04-22 03:00:48.000 48.000000 [Good (Interpolated)] 4.000000 [Good (Raw)] 40[Good (Raw)] 2015-04-22 03:00:50.000 50.000 [Good (Raw)] 27000000 [Good (Interpolated)] 45 [Good (Interpolated)] 2015-04-22 03:00:52.000 52.000000 [Good (Interpolated)] 50 [Good (Raw)] 50 [Good (Raw)] 5000000 [Good (Interpolated)] 54 000000 [Good (Interpolated)] 54 000000 [Good (Interpolated)] 54 000000 [Good (Interpolated)[Good (Interpolated)] 2015-04-22 03:01:12.000 72.000000 [Good (Interpolated)] 60.000 [Good (Raw)] 60 [Good (Raw)] 2015-04-22 03:01:17.000 70.000 [Good (Interpolated)] 70.000 [Good (Raw)] 70.000 [Good (Interpolated)[Good (Interpolated)] 70 [Good (Interpolated)] 2015-04-22 03:01:23.000 83.000000 [Good (Interpolated)] 70.000 [Good (Raw)] 70 [Good (Raw)] 2015-04-22 03:01:26.000 86.000000 [Good (Interpolated)] 80.000 [Good (Raw)] 80 [Good (Raw)] 2015-04-22 03:01:30.000 90.000 [Good (Raw)] 90 [Good (Raw)]

用标记绘制数据以展示方法如何工作。

次要情节(2,1,1);情节(dataSample“标记”'。');hold所有绘图(Dataintersect,“标记”“o”“线型”“没有”);标题(“数据对象中时间序列的交集”);次要情节(2,1,2);情节(dataSample“标记”'。');hold所有情节(dataUnion“标记”“o”“线型”“——”);标题('数据对象中的时间序列联盟');

在指定的时间步骤中重新确定小数据集。

Newts = DataSample(1).timestamp(1):秒(5):DataMple(1).timestamp(END);DatareSampled =重组(DataSample,Newts)图;绘图(数据群);hold所有绘图(Datares采样,“标记”“x”'linestyle'“没有”);
dataResampled = 1 × 3 OPC UA时间戳双浮子Int32  ----------------------- ----------------------------------- ----------------------------------- ------------------------------------ 2015-04-22 03:00:10.000 10.000000(好(生))13.478261(好(插值))13(好(插值))2015-04-22 03:00:15.000 15.000000(好(插值))15.652174(好(插值)]16[好(插值)]2015-04-22 03:00:20.000 20.000000[好(生)]17.826086[好(插值)]18[好(插值)]2015-04-22 03:00:25.000 25.000000[好(插值)]20.000000[好(生)]20[好(生)]2015-04-22 03:00:30.000 30.000000[好(生)]25.833334[好(插值)]26(好(插值))2015-04-22 03:00:35.000 35000000 [Good (Interpolated)] 27.916666 [Good (Interpolated)] 28 [Good (Interpolated)] 2015-04-22 03:00:40.000 40000 [Bad (Raw)] 3000000 [Good (Raw)] 30 [Good (Raw)] 2015-04-22 03:00:45.000 45000000 [Good (Interpolated)] 2.000000 [Good (Interpolated)] 20 [Good (Interpolated)] 2015-04-22 03:00:50.000 50000000 [Good (Interpolated)(生)]27.000000[好(插值)]45[好(插值)]2015-04-22 03:00:55.000 55.000000[好(插值)]51.500000[好(插值)]52[好(插值)]2015-04-22 03:01:00.000 60.000000[好(生)]54.000000[好(插值)]54[好(插值)]2015-04-22 03:01:05.000 65.000000(好(插值))56.500000[好(插值)]57[好(插值)]2015-04-22 03:01:10.000 70.000000(不确定(生))59.000000[好(插值)]59[好(插值)]2015-04-22 03:01:15.000 75.000000[好(插值)]66.000000[好(插值)]66[好(插值)]2015-04-22 03:01:20.000 80.000000(好(生))70.000000(好(插值))70[Good (Interpolated)] 2015-04-22 03:01:25.000 85.000000 [Good (Interpolated)] 76.666664 [Good (Interpolated)] 77 [Good (Interpolated)] 2015-04-22 03:01:30.000 90.000000 [Good (Raw)] 90.000000 [Good (Raw)] 90 [Good (Raw)]

按质量过滤数据

只发现重采样数据集的第二个元素的良好数据

resampledGood = filterByQuality (dataResampled (2),‘好’
重新制动= 1-by-1 OPC UA数据对象数组:时间戳浮动------------------------------------------------------ 2015-04-22 03:00:10.000 13.478261 [良好(内容)] 2015-04-22 03:00:15.00015.652174 [良好(内容)] 2015-04-22 03:00:20.000 17.826086 [良好(内容)] 2015-04-22 03:00:25.000 20.000000 [Good(RAW)] 2015-04-22 03:00:30.000 25.833334 [良好(内插)] 2015-04-22 03:00:35.000 27.916666 [良好(内容)] 2015-04-22 03:00:40.000 30.000000 [Good(RAW)] 2015-04-22 03:00:45.000 2.000000 [良好(插值)] 2015-04-22 03:00:50.000 27.000000 [良好(内插)] 2015-04-22 03:00:55.000 51.500000 [良好(内容)] 2015-04-22 03:01:00.000 54.000000 [良好(插值)] 2015-04-22 03:01:05.000 56.500000 [良好(内容)] 2015-04-22 03:01:10.000 59.000000 [良好(内插)] 2015-04-22 03:01:15.000 66.000000 [良好(插值)] 2015-04-22 03:01:20.000 70.000000 [良好(内容)] 2015-04-22 03:01:25.000 76.666664 [良好(内容)] 2015-04-22 03:01:30.000 90.000000 [好(RAW)]

过滤重采样数据的第二个元素以仅返回内插数据。使用原件可视化过滤的数据。

resampledInterpolated = filterByQuality (dataResampled (2),“起源”'内插')图;绘图(Datares采样(2))持有情节(resampledGood“标记”“+”'linestyle'“没有”'displayname'‘好’);绘图(重新制定的Interplated,“标记”“x”'linestyle'“没有”'displayname'“插入”);传奇(“位置”'西北'
resampledInterpolated = 1 × 1 OPC UA时间戳的浮动  ----------------------- ----------------------------------- 2015-04-22 03:00:10.000 13.478261[好(插值)]2015-04-22 03:00:15.000 15.652174[好(插值)]2015-04-22 03:00:20.000 17.826086[好(插值)]2015-04-22 03:00:30.000 25.833334[好(插值)]2015-04-22 03:00:35.000 27.916666[好[Good (Interpolated)] 2015-04-22 03:00:45.000 2.000000 [Good (Interpolated)] 2015-04-22 03:00:50.000 27000000 [Good (Interpolated)] 2015-04-22 03:00:55.000 5500000 [Good (Interpolated)] 2015-04-22 03:01:05.000 54.000000 [Good (Interpolated)] 2015-04-22 03:01:05.000 56.500000 [Good (Interpolated)] 2015-04-22 03:01:10.000 59.000000 [Good (Interpolated)]2015-04-22 03:01:15.000 66.000000 [Good (Interpolated)] 2015-04-22 03:01:20.000 70.000000 [Good (Interpolated)] 2015-04-22 03:01:25.000 76.666664 [Good (Interpolated)]