Read Data from MDF Files - MATLAB & Simulink Example (2024)

Open Live Script

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/Bdoc24a_2528353_1101874/tp8faccd1d/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

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 { 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 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 = 1x1 cell array {751x8 timetable}
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 { 751x2 timetable} {92033x1 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 {751x2 timetable} { 0x0 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 { 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 ⋮

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 {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 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 {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 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 { 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 2022-01-20 01:22:34.080000000 1685.4 0 59.893 1 150.76 776.41 35.847 0 2022-01-20 01:22:34.120000000 1907.2 0 59.839 1 193.42 973.15 65.768 0 2022-01-20 01:22:34.160000000 2062 0 59.785 1 227.02 1117.6 101.53 0 2022-01-20 01:22:34.200000000 2161.2 0 59.732 1 251.11 1212.8 141.45 0 2022-01-20 01:22:34.240000000 2221.4 0 59.678 1 267.24 1264.3 183.86 0 2022-01-20 01:22:34.280000000 2257.2 0 59.624 1 276.35 1271.2 227.25 0 2022-01-20 01:22:34.320000000 2278.7 0 59.57 1 281.99 1259.5 270.52 0 2022-01-20 01:22:34.360000000 2292.4 0 59.517 1 283.39 1229 313.08 0 2022-01-20 01:22:34.400000000 2305.1 0 59.463 1 283.29 1193.4 354.43 0 2022-01-20 01:22:34.440000000 2317.4 0 59.409 1 282.91 1156.6 394.58 0 2022-01-20 01:22:34.480000000 2330.5 0 59.356 1 281.84 1112.8 433.27 0 2022-01-20 01:22:34.520000000 2344.5 0 59.302 1 281.19 1073.1 470.53 0 2022-01-20 01:22:34.560000000 2359.1 0 59.248 1 279.77 1032.9 506.43 0 2022-01-20 01:22:34.600000000 2376.4 0 59.195 1 277.89 993.97 540.92 0 ⋮
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 ⋮
Read Data from MDF Files
- MATLAB & Simulink Example (2024)

FAQs

How to read data from MDF file? ›

SSMS Method to Learn How to Extract MDF File & View All Data
  1. Open SSMS in system & connect with SQL instance.
  2. Navigate to Object Explorer & right-click on databases.
  3. Now, Go to Attach & Click on Add button in the window.
  4. Browse to Select the MDF file from the system & Click Ok.
Jan 18, 2024

Can Matlab read MDF files? ›

The toolbox provides read and write access to MDF files.

How do I get Matlab to read data files? ›

Use fopen to open the file, specify the character encoding, and obtain the fileID value. When you finish reading, close the file by calling fclose(fileID) . A = fscanf( fileID , formatSpec , sizeA ) reads file data into an array, A , with dimensions, sizeA , and positions the file pointer after the last value read.

How to read data from Datastore in Matlab? ›

data = read( ds ) returns data from a datastore. Subsequent calls to the read function continue reading from the endpoint of the previous call. [ data , info ] = read( ds ) also returns information about the extracted data in info , including metadata.

What program opens MDF files? ›

SQL Server Management Studio (SSMS) is a powerful tool for managing SQL Server databases, including opening MDF files.

How do I export data from MDF? ›

Steps to export MDF to Excel format are as follows;
  1. Open SQL Server Object Explorer.
  2. Select the database you want to export from the list and right-click to select Tasks >> Export Data.
Mar 29, 2024

What file types can MATLAB read? ›

Category
  • Text Files.
  • Spreadsheets.
  • Image Data.
  • Scientific Data.
  • Audio and Video Data.
  • Structured Data and XML Documents.
  • JSON Format.

How to read PDB file in MATLAB? ›

PDBStruct = pdbread( File ) reads data from a PDB-formatted text file and stores the data in a structure containing a field for each PDB record. PDBStruct = pdbread( File , Name=Value ) uses additional options specified by one or more name-value arguments.

What file format is MDF? ›

MDF (Measurement Data Format) is a binary file format to store recorded or calculated data for post-measurement processing, off-line evaluation or long-term storage. The format has become a de-facto standard for measurement & calibration systems (MC-systems), but is also used in many other application areas.

How to extract data into MATLAB? ›

Usually, the easiest way to import text data into MATLAB is to use the extractFileText function. This function extracts the text data from text, PDF, HTML, and Microsoft Word files. To import text from CSV and Microsoft Excel files, use readtable . To extract text from HTML code, use extractHTMLText .

What is the command to read a file in MATLAB? ›

To call a MEX file, put the file on your MATLAB® path. Then type the name of the file, without the file extension. If you have MEX file source code, see Build C MEX Function for information about creating the executable function.

How do I load data from Mat-file in MATLAB? ›

To load saved variables from a MAT-file into your workspace, double-click the MAT-file in the Current Folder browser. To load a subset of variables from a MAT-file on the Home tab, in the Variable section, click Import Data. Select the MAT-file you want to load and click Open.

How to read large data in MATLAB? ›

Import Large Data Sets into MATLAB

To manage the MATLAB memory, process your data in parts. Use the fetch function to limit the number of rows your query returns by using the 'MaxRows' input argument. Using a MATLAB script, you can import data in increments until all data is retrieved.

What is the function to read data in MATLAB? ›

You can read text data with the readline function. The readline function reads data until the first occurrence of the terminator and returns it as a string without the terminator. You can read binary data with the read function.

How do I view an MDF file? ›

5 Quick Steps for MDF File Opener
  1. Step-1. Launch Tool to Open MDF File of SQL in System.
  2. Step-2. Add MDF File using the Add File Button.
  3. Step-3. Select Quick or Advance Scan Option.
  4. Step-4. Open and View MDF Files in System.
  5. Step-5. Close the MDF File Opener Finally.
Mar 31, 2024

How can I open MDF file without SQL Server? ›

So, we recommend you rely on the Aryson SQL Database Recovery Software, which lets users open and read Master Database File(. mdf( without SQL Server. It supports a corrupted, damaged, or inaccessible MDF file and displays all the data in well-details. The software helps users recover data from corrupted SQL MDF files.

How do I open an MDF file on my PC? ›

Opening an MDF File
  1. Launch SQL Server Management Studio (or your system's MDF file opener).
  2. Connect to the SQL server on your device.
  3. Right-click the “Database” folder in the right panel.
  4. Select Attach → Add.
  5. Select the MDF file you want to open and click Ok.
Jun 7, 2024

How do I read data from a .DB file? ›

File > Import Data > Database > New Query... Select the data source. If necessary (depending on the data source), select the database file and/or enter a login name, password, and other information.

References

Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6173

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.