Main Content

Transition Your mdf Object Code

With the mdf object and its functions no longer recommended, you should update your code to directly access the MDF file, as shown for the following common tasks.

Read Metadata

TaskObject FunctionalityUse This Instead

Get initial timestamp from metadata.

mdfObj = mdf("MyFile.MF4");
initTime = mdfObj.InitialTimestamp;
info = mdfInfo("MyFile.MF4");
initTime = info.InitialTimestamp;

Get metadata for all channel groups in a file.

mdfObj = mdf("MyFile.MF4");
chanGrpInfo = mdfObj.ChannelGroup;
chanGrpInfo = mdfChannelGroupInfo("MyFile.MF4");
Get metadata for all channels in channel group 2.
mdfObj = mdf("MyFile.MF4");
chanInfo = mdfObj.ChannelGroup(2).Channel;
chanInfo = mdfChannelInfo("MyFile.MF4", GroupNumber=2);
Get metadata about all channels in a file.
mdfObj = mdf("MyFile.MF4");
chanInfo = channelList(mdfObj);
chanInfo = mdfChannelInfo("MyFile.MF4");
Get metadata about specific channels.
mdfObj = mdf("MyFile.MF4");
chanInfo = channelList(mdfObj, "XYZ", ExactMatch=true);
chanInfo = mdfChannelInfo("MyFile.MF4", Channel="XYZ");
Get metadata about partially matched channels.
mdfObj = mdf("MyFile.MF4");
chanInfo = channelList(mdfObj, "XYZ");
chanInfo = mdfChannelInfo("MyFile.MF4", Channel="*XYZ*");

Read Data

TaskObject FunctionalityUse This Instead
Read all data from a file.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj);
data = mdfRead("MyFile.MF4");
Read all data in channel group 2.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, 2);
data = mdfRead("MyFile.MF4", GroupNumber=2);
Read data in channels chan1 and chan2 in channel group 2.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, 2, ["chan1","chan2"]);
data = mdfRead("MyFile.MF4", GroupNumber=2, Channels=["chan1","chan2"]);
Read data in the time range of 5 to 10 seconds.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, 2, ["chan1","chan2"], seconds(5), seconds(10));
data = mdfRead("MyFile.MF4", GroupNumber=2, ...
           Channels=["chan1","chan2"], TimeRange=seconds([5,10]));
Read data in the index range of 50 to 100.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, 2, ["chan1","chan2"], 50, 100);
data = mdfRead("MyFile.MF4", GroupNumber=2, ...
           Channels=["chan1","chan2"], IndexRange=[50,100]);
Read data as a vector or timeseries.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, OutputFormat="vector");

No direct equivalent. The only supported output is a timetable. Read each column (variable) of the returned timetable as a vector or timeseries. See Timetables.

Read data with only numeric-to-numeric conversion formulas applied.
mdfObj = mdf("MyFile.MF4");
data = read(mdfObj, Conversion="numeric");

No direct equivalent. For specific channel requirements you can read physical data (value-to-value conversions) or raw data (value-to-text, text-to-value, and text-to-text conversions):

data = mdfRead("MyFile.MF4", Channels=physChans, ReadRaw=false); % Default
data = mdfRead("MyFile.MF4", Channels=rawChans, ReadRaw=true);

See Read Physical and Raw Data from MDF Files.

Save Attachments

TaskObject FunctionalityUse This Instead
Save an MDF file attached file.
mdfObj = mdf("MyFile.MF4");
saveAttachment(mdfObj, "MyDB.dbc");
mdfSaveAttachment("MyFile.MF4", Attachment="MyDB.dbc");
Save an attachment to a specified folder.
mdfObj = mdf("MyFile.MF4");
saveAttachment(mdfObj, "MyDB.dbc", "C:\MyDB.dbc");
mdfSaveAttachment("MyFile.MF4", Attachment="MyDB.dbc", OutputFolder="C:\");
Save an attachment with a new name.
mdfObj = mdf("MyFile.MF4");
saveAttachment(mdfObj, "MyDB.dbc", "RenamedDB.dbc");

No direct equivalent. Save the attachment and then rename the file.

See Also

Functions