What is a .mat file?
MATLAB Data File · Data · MathWorks · 1996
A .mat file stores variables from MATLAB: matrices, arrays, structures and more. It is the standard way to save and load a MATLAB workspace, and it is widely read in Python for scientific work.
What is a .mat file used for?
The version 5 MAT file starts with the text header MATLAB 5.0 MAT-file, followed by the stored variables in binary. The newer version 7.3 format is actually an HDF5 file, used for very large data.
Beyond MATLAB, SciPy in Python reads and writes .mat files (scipy.io.loadmat), so the format is common in research even outside MATLAB.
How to open a .mat file
The .mat format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .mat file.
Windows
- MATLAB
- GNU Octave
- Python (scipy.io)
macOS
- MATLAB
- GNU Octave
- Python (scipy.io)
Linux
- GNU Octave
- Python (scipy.io)
- MATLAB
How to convert a .mat file
You can convert a .mat file to csv, hdf5, npy using a conversion tool or the export menu of an app that opens it.
.mat file signature (magic bytes)
Programs recognise a .mat file by the bytes at the start of the file, not by its name. These are the signatures for MAT. For a full breakdown, see the MAT file signature page.
| Hex signature | Offset | Note |
|---|---|---|
| 4D 41 54 4C 41 42 20 35 2E 30 | 0 | 'MATLAB 5.0' (v5 format; v7.3 is HDF5) |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .mat file?
A .mat file stores variables from MATLAB: matrices, arrays, structures and more. It is the standard way to save and load a MATLAB workspace, and it is widely read in Python for scientific work.
How do I open a .mat file without MATLAB?
Use GNU Octave, which is free and largely MATLAB-compatible, or read it in Python with scipy.io.loadmat.
What is inside a .mat file?
Saved MATLAB variables: matrices, arrays, structs and cell arrays, stored in binary with a text header naming the format version.
Why won't scipy load my .mat file?
Version 7.3 MAT files are HDF5, which older scipy.io.loadmat cannot read. Use the h5py library, or the mat73 package, for v7.3 files.
Related formats
Sources
Details on this page were checked against authoritative references: