从 mdf 文件中读取数据 -凯发k8网页登录
以下示例说明如何从 mdf 文件中读取通道数据。
查看文件详细信息
通过指定文件名,使用 查看 mdf 文件的元数据。
fileinfo = mdfinfo("vehicledata.mf4")
fileinfo = mdfinfo with properties: file details name: "vehicledata.mf4" path: "/tmp/bdoc23a_2181783_2332753/tp3fb84b34/vnt-ex94427230/vehicledata.mf4" author: "" department: "" project: "" subject: "" comment: "example file demonstrating workflows of writing to mdf files." version: "4.10" initialtimestamp: 2022-01-20 01:22:34.000000000 creator details programidentifier: "matlab" creatorvendorname: "the mathworks, inc." creatortoolname: "matlab" creatortoolversion: "9.12.0.1846952 (r2022a) prerelease update 1" creatorusername: "" creatorcomment: "" file contents attachment: [1x7 table] channelgroupcount: 2
从 mdf 文件中读取所有数据
从 mdf 文件中读取所有数据的最简单方法是只使用文件名调用 函数。每个时间表表示从对应的通道组读取的数据。
dataall = mdfread("vehicledata.mf4")
dataall=2×1 cell array
{ 751x8 timetable}
{92033x2 timetable}
dataall{1}
ans=751×8 timetable
time enginerpm brake throttle gear impellertorque outputtorque transmissionrpm vehiclespeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
0 sec 1000 0 60 1 52.919 282.65 0 0
0.04 sec 1383.3 0 59.946 1 101.4 532.63 13.593 0.30047
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0.7924
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 1.4538
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 2.2443
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 3.1268
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 4.0644
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 5.0234
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 5.9798
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 6.9208
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 7.8348
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 8.7222
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 9.5775
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 10.401
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 11.195
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 11.957
⋮
dataall{2}
ans=92033×2 timetable
time airflow fuelrate
______________ _______ ________
0 sec 17.294 1.209
0.00056199 sec 17.263 1.209
0.0033719 sec 17.112 1.209
0.01 sec 16.776 1.1729
0.02 sec 16.316 1.1409
0.03 sec 15.907 1.1124
0.04 sec 15.546 1.0873
0.05 sec 15.228 1.0652
0.055328 sec 15.075 1.0652
0.055328 sec 15.075 1.0652
0.055328 sec 15.075 1.0652
0.06 sec 14.949 1.0458
0.064672 sec 14.832 1.0458
0.07 sec 14.707 1.0289
0.08 sec 14.497 1.0143
0.09 sec 14.317 1.0019
⋮
从所选通道组读取数据
要仅从所选通道组读取数据,请将选项 groupnumber
指定为目标通道组编号。仅从通道组 1 读取数据。
datachangrp1 = mdfread("vehicledata.mf4", groupnumber=1)
datachangrp1 = 1x1 cell array
{751x8 timetable}
datachangrp1{1}
ans=751×8 timetable
time enginerpm brake throttle gear impellertorque outputtorque transmissionrpm vehiclespeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
0 sec 1000 0 60 1 52.919 282.65 0 0
0.04 sec 1383.3 0 59.946 1 101.4 532.63 13.593 0.30047
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0.7924
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 1.4538
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 2.2443
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 3.1268
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 4.0644
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 5.0234
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 5.9798
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 6.9208
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 7.8348
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 8.7222
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 9.5775
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 10.401
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 11.195
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 11.957
⋮
从匹配指定名称的通道中读取数据
要从完全已知的通道名称中读取数据,请将选项 channel
指定为精确的通道名称。从名为“brake”、“throttle”和“fuelrate”的通道读取数据。
datachanexact = mdfread("vehicledata.mf4", channel=["brake", "throttle", "fuelrate"])
datachanexact=2×1 cell array
{ 751x2 timetable}
{92033x1 timetable}
请注意,数据以两个时间表的形式返回。这是因为通道“brake”和“throttle”存在于通道组 1 中,而通道“fuelrate”存在于通道组 2 中。
datachanexact{1}
ans=751×2 timetable
time brake throttle
________ _____ ________
0 sec 0 60
0.04 sec 0 59.946
0.08 sec 0 59.893
0.12 sec 0 59.839
0.16 sec 0 59.785
0.2 sec 0 59.732
0.24 sec 0 59.678
0.28 sec 0 59.624
0.32 sec 0 59.57
0.36 sec 0 59.517
0.4 sec 0 59.463
0.44 sec 0 59.409
0.48 sec 0 59.356
0.52 sec 0 59.302
0.56 sec 0 59.248
0.6 sec 0 59.195
⋮
datachanexact{2}
ans=92033×1 timetable
time fuelrate
______________ ________
0 sec 1.209
0.00056199 sec 1.209
0.0033719 sec 1.209
0.01 sec 1.1729
0.02 sec 1.1409
0.03 sec 1.1124
0.04 sec 1.0873
0.05 sec 1.0652
0.055328 sec 1.0652
0.055328 sec 1.0652
0.055328 sec 1.0652
0.06 sec 1.0458
0.064672 sec 1.0458
0.07 sec 1.0289
0.08 sec 1.0143
0.09 sec 1.0019
⋮
要从部分已知的通道名称中读取数据,请使用通配符指定选项 channel
。从名称包含子字符串“torque”的通道中读取数据。
datachanwildcard = mdfread("vehicledata.mf4", channel="*torque*")
datachanwildcard=2×1 cell array
{751x2 timetable}
{ 0x0 timetable}
请注意,索引 2 处的时间表为空。这是因为所有匹配“*torque*”的通道都存在于通道组 1 中。
datachanwildcard{1}
ans=751×2 timetable
time impellertorque outputtorque
________ ______________ ____________
0 sec 52.919 282.65
0.04 sec 101.4 532.63
0.08 sec 150.76 776.41
0.12 sec 193.42 973.15
0.16 sec 227.02 1117.6
0.2 sec 251.11 1212.8
0.24 sec 267.24 1264.3
0.28 sec 276.35 1271.2
0.32 sec 281.99 1259.5
0.36 sec 283.39 1229
0.4 sec 283.29 1193.4
0.44 sec 282.91 1156.6
0.48 sec 281.84 1112.8
0.52 sec 281.19 1073.1
0.56 sec 279.77 1032.9
0.6 sec 277.89 993.97
⋮
使用表从通道读取数据
您可以使用 来过滤目标通道,然后在 mdfread
中使用获得的表来仅读取列出的通道。
首先,使用 mdfchannelinfo
找到与“*rpm”或“airflow”匹配的通道名称。
chaninfo = mdfchannelinfo("vehicledata.mf4", channel=["*rpm", "airflow"])
chaninfo=3×13 table name groupnumber groupnumsamples groupacquisitionname groupcomment groupsourcename groupsourcepath displayname unit comment extendednameprefix sourcename sourcepath _________________ ___________ _______________ ____________________ ___________________________________________________________________________ _______________ _______________ ___________ ____ ___________ __________________ ___________ ___________ "airflow" 2 92033simulation of engine gas dynamics. "" g/s "enginerpm" 1 751 simulation of an automatic transmission controller during passing maneuver. "" rpm "transmissionrpm" 1 751 simulation of an automatic transmission controller during passing maneuver. "" rpm
通过将可选参数 channel
指定为 mdfchannelinfo
返回的表,使用 mdfread
函数。这将从 chaninfo
表中列出的三个通道中一次性读取数据。
datachantable = mdfread("vehicledata.mf4", channel=chaninfo)
datachantable=2×1 cell array
{ 751x2 timetable}
{92033x1 timetable}
datachantable{1}
ans=751×2 timetable
time enginerpm transmissionrpm
________ _________ _______________
0 sec 1000 0
0.04 sec 1383.3 13.593
0.08 sec 1685.4 35.847
0.12 sec 1907.2 65.768
0.16 sec 2062 101.53
0.2 sec 2161.2 141.45
0.24 sec 2221.4 183.86
0.28 sec 2257.2 227.25
0.32 sec 2278.7 270.52
0.36 sec 2292.4 313.08
0.4 sec 2305.1 354.43
0.44 sec 2317.4 394.58
0.48 sec 2330.5 433.27
0.52 sec 2344.5 470.53
0.56 sec 2359.1 506.43
0.6 sec 2376.4 540.92
⋮
datachantable{2}
ans=92033×1 timetable
time airflow
______________ _______
0 sec 17.294
0.00056199 sec 17.263
0.0033719 sec 17.112
0.01 sec 16.776
0.02 sec 16.316
0.03 sec 15.907
0.04 sec 15.546
0.05 sec 15.228
0.055328 sec 15.075
0.055328 sec 15.075
0.055328 sec 15.075
0.06 sec 14.949
0.064672 sec 14.832
0.07 sec 14.707
0.08 sec 14.497
0.09 sec 14.317
⋮
读取索引范围内的数据
要仅读取指定索引范围内的数据子集,请指定选项 indexrange
以提供开始和结束索引。从两个通道组读取索引 101 和 105 之间的数据。
databyindex = mdfread("vehicledata.mf4", indexrange=[101, 105])
databyindex=2×1 cell array
{5x8 timetable}
{5x2 timetable}
databyindex{1}
ans=5×8 timetable
time enginerpm brake throttle gear impellertorque outputtorque transmissionrpm vehiclespeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
4 sec 3138.5 0 54.631 2 235.21 340.98 1964.5 43.427
4.04 sec 3151.6 0 54.577 2 234.57 340.09 1975.5 43.668
4.08 sec 3164.6 0 54.523 2 233.93 339.2 1986.3 43.908
4.12 sec 3177.6 0 54.47 2 233.29 338.31 1997.2 44.148
4.16 sec 3190.4 0 54.416 2 232.65 337.43 2008 44.387
databyindex{2}
ans=5×2 timetable
time airflow fuelrate
________ _______ ________
0.89 sec 19.421 1.3439
0.9 sec 19.492 1.3486
0.91 sec 19.562 1.3532
0.92 sec 19.631 1.3577
0.93 sec 19.699 1.3622
读取时间范围内的数据
要仅读取指定时间范围内的数据子集,请指定选项 timerange
以提供开始和结束时间。从两个通道组读取在 1.5 秒到 2 秒之间的数据。
databytime = mdfread("vehicledata.mf4", timerange=seconds([1.5, 2]))
databytime=2×1 cell array
{13x8 timetable}
{51x2 timetable}
databytime{1}
ans=13×8 timetable
time enginerpm brake throttle gear impellertorque outputtorque transmissionrpm vehiclespeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
1.52 sec 2969 0 57.96 1 240.51 574.51 1106.7 24.463
1.56 sec 3006.7 0 57.906 1 238.7 570.4 1125.9 24.887
1.6 sec 3044.4 0 57.852 1 237.26 567.2 1144.9 25.309
1.64 sec 3082.4 0 57.799 1 235.33 562.79 1163.8 25.727
1.68 sec 3120.3 0 57.745 1 233.87 559.47 1182.6 26.142
1.72 sec 3157.9 0 57.691 1 232.51 556.4 1201.3 26.555
1.76 sec 3195 0 57.638 1 231.18 553.41 1219.9 26.966
1.8 sec 3232 0 57.584 0 510.18 1093.3 1238.3 27.374
1.84 sec 2899.9 0 57.53 2 384.51 755.8 1268.9 28.048
1.88 sec 2742.1 0 57.477 2 327.29 607.68 1291.4 28.548
1.92 sec 2665.8 0 57.423 2 299 534.91 1310.4 28.967
1.96 sec 2631.3 0 57.369 2 284.28 496.35 1327.5 29.346
2 sec 2617.6 0 57.315 2 276.76 475.14 1343.7 29.702
databytime{2}
ans=51×2 timetable
time airflow fuelrate
________ _______ ________
1.5 sec 22.414 1.5385
1.51 sec 22.446 1.5405
1.52 sec 22.477 1.5425
1.53 sec 22.508 1.5445
1.54 sec 22.539 1.5464
1.55 sec 22.569 1.5484
1.56 sec 22.598 1.5502
1.57 sec 22.628 1.5521
1.58 sec 22.656 1.554
1.59 sec 22.685 1.5558
1.6 sec 22.713 1.5576
1.61 sec 22.741 1.5593
1.62 sec 22.768 1.5611
1.63 sec 22.795 1.5628
1.64 sec 22.822 1.5645
1.65 sec 22.849 1.5662
⋮
读取带绝对时间戳的数据
要返回基于 mdf 文件初始时间戳计算的 datetime
类型的绝对时间戳,请在调用 mdfread
时将选项 absolutetime
指定为 true
。
dataabstime = mdfread("vehicledata.mf4", absolutetime=true)
dataabstime=2×1 cell array
{ 751x8 timetable}
{92033x2 timetable}
dataabstime{1}
ans=751×8 timetable
time enginerpm brake throttle gear impellertorque outputtorque transmissionrpm vehiclespeed
_____________________________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
2022-01-20 01:22:34.000000000 1000 0 60 1 52.919 282.65 0 0
2022-01-20 01:22:34.040000000 1383.3 0 59.946 1 101.4 532.63 13.593 0.30047
2022-01-20 01:22:34.080000000 1685.4 0 59.893 1 150.76 776.41 35.847 0.7924
2022-01-20 01:22:34.120000000 1907.2 0 59.839 1 193.42 973.15 65.768 1.4538
2022-01-20 01:22:34.160000000 2062 0 59.785 1 227.02 1117.6 101.53 2.2443
2022-01-20 01:22:34.200000000 2161.2 0 59.732 1 251.11 1212.8 141.45 3.1268
2022-01-20 01:22:34.240000000 2221.4 0 59.678 1 267.24 1264.3 183.86 4.0644
2022-01-20 01:22:34.280000000 2257.2 0 59.624 1 276.35 1271.2 227.25 5.0234
2022-01-20 01:22:34.320000000 2278.7 0 59.57 1 281.99 1259.5 270.52 5.9798
2022-01-20 01:22:34.360000000 2292.4 0 59.517 1 283.39 1229 313.08 6.9208
2022-01-20 01:22:34.400000000 2305.1 0 59.463 1 283.29 1193.4 354.43 7.8348
2022-01-20 01:22:34.440000000 2317.4 0 59.409 1 282.91 1156.6 394.58 8.7222
2022-01-20 01:22:34.480000000 2330.5 0 59.356 1 281.84 1112.8 433.27 9.5775
2022-01-20 01:22:34.520000000 2344.5 0 59.302 1 281.19 1073.1 470.53 10.401
2022-01-20 01:22:34.560000000 2359.1 0 59.248 1 279.77 1032.9 506.43 11.195
2022-01-20 01:22:34.600000000 2376.4 0 59.195 1 277.89 993.97 540.92 11.957
⋮
dataabstime{2}
ans=92033×2 timetable
time airflow fuelrate
_____________________________ _______ ________
2022-01-20 01:22:34.000000000 17.294 1.209
2022-01-20 01:22:34.000561989 17.263 1.209
2022-01-20 01:22:34.003371932 17.112 1.209
2022-01-20 01:22:34.010000000 16.776 1.1729
2022-01-20 01:22:34.020000000 16.316 1.1409
2022-01-20 01:22:34.030000000 15.907 1.1124
2022-01-20 01:22:34.040000000 15.546 1.0873
2022-01-20 01:22:34.050000000 15.228 1.0652
2022-01-20 01:22:34.055327997 15.075 1.0652
2022-01-20 01:22:34.055327997 15.075 1.0652
2022-01-20 01:22:34.055327997 15.075 1.0652
2022-01-20 01:22:34.060000000 14.949 1.0458
2022-01-20 01:22:34.064672003 14.832 1.0458
2022-01-20 01:22:34.070000000 14.707 1.0289
2022-01-20 01:22:34.080000000 14.497 1.0143
2022-01-20 01:22:34.090000000 14.317 1.0019
⋮