Read Data from MDF Files
This example shows you how to read channel data from an MDF file.
View File Details
View metadata of an MDF file using mdfInfo
by specifying the file name.
fileInfo = mdfInfo("VehicleData.mf4")
fileInfo = MDFInfo with properties: File Details Name: "VehicleData.mf4" Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex94427230/VehicleData.mf4" Author: "Engineer" Department: "Automotive" Project: "Demo" Subject: "Prototype" Comment: "Example file" Version: "4.20" InitialTimestamp: 2024-11-14 19:16:35.000000000 Creator Details ProgramIdentifier: "MATLAB" CreatorVendorName: "The MathWorks, Inc." CreatorToolName: "MATLAB" CreatorToolVersion: "25.1.0.2768609 (R2025a) Prerelease" CreatorUserName: "engineer" CreatorComment: "Created with Vehicle Network Toolbox" File Contents Attachment: [1×7 table] ChannelGroupCount: 2 Event: [0×8 eventtable]
Read All Data from MDF File
The easiest way to read all data from an MDF file is to call the mdfRead
function with just the file name. Each timetable represents data read from the corresponding channel group.
dataAll = mdfRead("VehicleData.mf4")
dataAll=2×1 cell array
{ 751×8 timetable}
{92033×2 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
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 0
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 0
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 0
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 0
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 0
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 0
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 0
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 0
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 0
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 0
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 0
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 0
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮
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
⋮
Read Data from Selected Channel Groups
To read data only from selected channel groups, specify option GroupNumber
to be the targeted channel group numbers. Read data from channel group 1 only.
dataChanGrp1 = mdfRead("VehicleData.mf4", GroupNumber=1)
dataChanGrp1 = 1×1 cell array
{751×8 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
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 0
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 0
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 0
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 0
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 0
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 0
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 0
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 0
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 0
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 0
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 0
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 0
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮
Read Data from Channels Matching Specified Names
To read data from exactly known channel names, specify option Channel
to be the exact channel names. Read data from channels named "Brake", "Throttle" and "FuelRate".
dataChanExact = mdfRead("VehicleData.mf4", Channel=["Brake", "Throttle", "FuelRate"])
dataChanExact=2×1 cell array
{ 751×2 timetable}
{92033×1 timetable}
Note that data are returned in two timetables. This is because channels "Brake" and "Throttle" are present in channel group 1, while channel "FuelRate" is present in channel group 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
⋮
To read data from partially known channel names, specify option Channel
using wildcard characters. Read data from channels whose name contains substring "Torque".
dataChanWildcard = mdfRead("VehicleData.mf4", Channel="*Torque*")
dataChanWildcard=2×1 cell array
{751×2 timetable}
{ 0×0 timetable}
Note that the timetable at index 2 is empty. This is because all channels matching "*Torque*" are present in channel group 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
⋮
Read Data from Channels Using Table
You can use mdfChannelInfo
to filter for channels to target, and then use the obtained table in mdfRead
to only read from the listed channels.
First, find channel names matching "*RPM" or "AirFlow" using mdfChannelInfo
.
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 92033 <undefined> Simulation of engine gas dynamics. <undefined> <undefined> "" g/s <undefined> <undefined> <undefined> <undefined>
"EngineRPM" 1 751 <undefined> Simulation of an automatic transmission controller during passing maneuver. <undefined> <undefined> "" rpm <undefined> <undefined> <undefined> <undefined>
"TransmissionRPM" 1 751 <undefined> Simulation of an automatic transmission controller during passing maneuver. <undefined> <undefined> "" rpm <undefined> <undefined> <undefined> <undefined>
Use the mdfRead
function by specifying optional argument Channel
as the table returned by mdfChannelInfo
. This reads data from the three channels listed in the chanInfo
table in one go.
dataChanTable = mdfRead("VehicleData.mf4", Channel=chanInfo)
dataChanTable=2×1 cell array
{ 751×2 timetable}
{92033×1 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
⋮
Read Data Within Index Range
To read only a subset of data within a specified index range, specify option IndexRange
to provide the start and end index. Read data from both channel groups between index 101 and 105.
dataByIndex = mdfRead("VehicleData.mf4", IndexRange=[101, 105])
dataByIndex=2×1 cell array
{5×8 timetable}
{5×2 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 0
4.04 sec 3151.6 0 54.577 2 234.57 340.09 1975.5 0
4.08 sec 3164.6 0 54.523 2 233.93 339.2 1986.3 0
4.12 sec 3177.6 0 54.47 2 233.29 338.31 1997.2 0
4.16 sec 3190.4 0 54.416 2 232.65 337.43 2008 0
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
Read Data Within Time Range
To read only a subset of data within a specified time range, specify option TimeRange
to provide the start and end time. Read data from both channel groups between 1.5 seconds and 2 seconds.
dataByTime = mdfRead("VehicleData.mf4", TimeRange=seconds([1.5, 2]))
dataByTime=2×1 cell array
{13×8 timetable}
{51×2 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 0
1.56 sec 3006.7 0 57.906 1 238.7 570.4 1125.9 0
1.6 sec 3044.4 0 57.852 1 237.26 567.2 1144.9 0
1.64 sec 3082.4 0 57.799 1 235.33 562.79 1163.8 0
1.68 sec 3120.3 0 57.745 1 233.87 559.47 1182.6 0
1.72 sec 3157.9 0 57.691 1 232.51 556.4 1201.3 0
1.76 sec 3195 0 57.638 1 231.18 553.41 1219.9 0
1.8 sec 3232 0 57.584 2 510.18 1093.3 1238.3 0
1.84 sec 2899.9 0 57.53 2 384.51 755.8 1268.9 0
1.88 sec 2742.1 0 57.477 2 327.29 607.68 1291.4 0
1.92 sec 2665.8 0 57.423 2 299 534.91 1310.4 0
1.96 sec 2631.3 0 57.369 2 284.28 496.35 1327.5 0
2 sec 2617.6 0 57.315 2 276.76 475.14 1343.7 0
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
⋮
Read Data with Absolute Timestamps
To return absolute timestamps in datetime
that takes into account the initial timestamp of the MDF file, specify option AbsoluteTime
as true
when calling mdfRead
.
dataAbsTime = mdfRead("VehicleData.mf4", AbsoluteTime=true)
dataAbsTime=2×1 cell array
{ 751×8 timetable}
{92033×2 timetable}
dataAbsTime{1}
ans=751×8 timetable
time EngineRPM Brake Throttle Gear ImpellerTorque OutputTorque TransmissionRPM VehicleSpeed
_____________________________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
2024-11-14 19:16:35.000000000 1000 0 60 1 52.919 282.65 0 0
2024-11-14 19:16:35.040000000 1383.3 0 59.946 1 101.4 532.63 13.593 0
2024-11-14 19:16:35.080000000 1685.4 0 59.893 1 150.76 776.41 35.847 0
2024-11-14 19:16:35.120000000 1907.2 0 59.839 1 193.42 973.15 65.768 0
2024-11-14 19:16:35.160000000 2062 0 59.785 1 227.02 1117.6 101.53 0
2024-11-14 19:16:35.200000000 2161.2 0 59.732 1 251.11 1212.8 141.45 0
2024-11-14 19:16:35.240000000 2221.4 0 59.678 1 267.24 1264.3 183.86 0
2024-11-14 19:16:35.280000000 2257.2 0 59.624 1 276.35 1271.2 227.25 0
2024-11-14 19:16:35.320000000 2278.7 0 59.57 1 281.99 1259.5 270.52 0
2024-11-14 19:16:35.360000000 2292.4 0 59.517 1 283.39 1229 313.08 0
2024-11-14 19:16:35.400000000 2305.1 0 59.463 1 283.29 1193.4 354.43 0
2024-11-14 19:16:35.440000000 2317.4 0 59.409 1 282.91 1156.6 394.58 0
2024-11-14 19:16:35.480000000 2330.5 0 59.356 1 281.84 1112.8 433.27 0
2024-11-14 19:16:35.520000000 2344.5 0 59.302 1 281.19 1073.1 470.53 0
2024-11-14 19:16:35.560000000 2359.1 0 59.248 1 279.77 1032.9 506.43 0
2024-11-14 19:16:35.600000000 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮
dataAbsTime{2}
ans=92033×2 timetable
time AirFlow FuelRate
_____________________________ _______ ________
2024-11-14 19:16:35.000000000 17.294 1.209
2024-11-14 19:16:35.000561989 17.263 1.209
2024-11-14 19:16:35.003371932 17.112 1.209
2024-11-14 19:16:35.010000000 16.776 1.1729
2024-11-14 19:16:35.020000000 16.316 1.1409
2024-11-14 19:16:35.030000000 15.907 1.1124
2024-11-14 19:16:35.040000000 15.546 1.0873
2024-11-14 19:16:35.050000000 15.228 1.0652
2024-11-14 19:16:35.055327997 15.075 1.0652
2024-11-14 19:16:35.055327997 15.075 1.0652
2024-11-14 19:16:35.055327997 15.075 1.0652
2024-11-14 19:16:35.060000000 14.949 1.0458
2024-11-14 19:16:35.064672003 14.832 1.0458
2024-11-14 19:16:35.070000000 14.707 1.0289
2024-11-14 19:16:35.080000000 14.497 1.0143
2024-11-14 19:16:35.090000000 14.317 1.0019
⋮