read

Read channel data from MDF-file

Description

example

data = read(mdfObj) reads all data for all channels from the MDF-file identified by the MDF-file object mdfObj, and assigns the output to data. If the file data is one channel group, the output is a timetable; multiple channel groups are returned as a cell array of timetables, where the cell array index corresponds to the channel group number.

example

data = read(mdfObj,chanList) reads all data for all channels specified in the channel list table chanList.

example

data = read(mdfObj,chanGroupIndex,chanName) reads all data for the specified channel from the MDF-file identified by the MDF-file object mdfObj.

example

data = read(mdfObj,chanGroupIndex,chanName,startPosition) reads data from the position specified by startPosition.

example

data = read(mdfObj,chanGroupIndex,chanName,startPosition,endPosition) reads data for the range specified from startPosition to endPosition.

example

data = read(mdfObj,chanGroupIndex,chanName,startPosition,endPosition,'OutputFormat',fmtType) returns data with the specified output format.

example

[data,time] = read(mdfObj,chanGroupIndex,chanName,startPosition,endPosition,'OutputFormat','Vector') returns two vectors of channel data and corresponding timestamps.

Examples

collapse all

Read all available data from the MDF-file.

mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj);

Read all available data from the MDF-file for channels specified as part of a channel list.

mdfObj = mdf('MDFFile.mf4');
chanList = channelList(mdfObj) % Channel table
data = read(mdfObj,chanList(1:3,:)); % First 3 channels

Read all available data from the MDF-file for specified channels.

mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'});

Read a range of data from the MDF-file using indexing for startPosition and endPosition to specify the data range.

mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'},1,10);

Read a range of data from the MDF-file using time values for startPosition and endPosition to specify the data range.

mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'},seconds(5.5),seconds(7.3));

Read all available data from the MDF-file, returning data and time vectors.

mdfObj = mdf('MDFFile.mf4');
[data,time] = read(mdfObj,1,'Channel1','OutputFormat','Vector');

Read all available data from the MDF-file, returning time series data.

mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,'Channel1','OutputFormat','TimeSeries');

Read data from a channel identified by the channelList function.

Get list of channels and display their names and group numbers.

mdfObj = mdf('File05.mf4');
chlist = channelList(mdfObj);
chlist(1:2,1:2) % Display 2 channels, 2 columns
  2×2 table

                ChannelName                 ChannelGroupNumber
    ____________________________________    __________________

    "Float_32_LE_Offset_64"                         2         
    "Float_64_LE_Master_Offset_0"                   2

Read data from the first channel in the list.

data = read(mdfObj,chlist{1,2},chlist{1,1});
data(1:5,:)
  5×1 timetable

      Time      Float_32_LE_Offset_64
    ________    _____________________

    0 sec                  5         
    0.01 sec             5.1         
    0.02 sec             5.2         
    0.03 sec             5.3         
    0.04 sec             5.4

Input Arguments

collapse all

MDF-file, specified as an MDF-file object.

Example: mdf('MDFFile.mf4')

List of channels, specified as a table in the format returned by the channelList (Vehicle Network Toolbox) function.

Example: channelList()

Data Types: table

Index of channel group, specified as a numeric value that identifies the channel group from which to read.

Example: 1

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name of channel, specified as a character vector, string, or array. chanName identifies the name of a channel in the channel group. Use a cell array of character vectors or array of string to identify multiple channels.

Example: 'Channel1'

Data Types: char | string | cell

First position of channel data, specified as a numeric value or duration. The startPosition option specifies the first position from which to read channel data. Provide a numeric value to specify an index position; use a duration to specify a time position. If only startPosition is provided without the endPosition option, the data value at that location is returned. When used with endPosition to specify a range, the function returns data from the startPosition (inclusive) to the endPosition (noninclusive).

Example: 1

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | duration

Last position of channel data range, specified as a numeric value or duration. The endPosition option specifies the last position for reading a range of channel data. Provide both the startPosition and endPosition to specify retrieval of a range of data. The function returns up to but not including endPosition when reading a range. Provide a numeric value to specify an index position; use a duration to specify a time position.

Example: 1000

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | duration

Format for output data, specified as a character vector or string. This option formats the output according to the following table.

OutputFormatDescription
'Timetable'

Return a timetable from one or more channels into one output variable. This is the only format allowed when reading from multiple channels at the same time. (Default.)

Note: The timetable format includes columns for the MDF channels. Because the column titles must be valid MATLAB® identifiers, they might not be exactly the same as those values in the MDF object ChannelNames property. The column headers are derived from the property using the function matlab.lang.makeValidName. The original channel names are available in the VariableDescriptions property of the timetable object.

'Vector'Return a vector of numeric data values, and optionally a vector of time values from one channel. Use one output variable to return only data, or two output variables to return both data and time vectors.
'TimeSeries'Return a time series of data from one channel.

Example: 'Vector'

Data Types: char | string

Output Arguments

collapse all

Channel data, returned as vector of doubles, a time series, a timetable, or cell array of timetables, according to the 'OutputFormat' option setting and the number of channel groups.

Channel data times, returned as a vector of double elements. The time vector is returned only when the 'OutputFormat' is set to 'Vector'.

See Also

Functions

Introduced in R2016b