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.
What opens 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.
Windows
- MATLAB
- GNU Octave
- Python (scipy.io)
macOS
- MATLAB
- GNU Octave
- Python (scipy.io)
Linux
- GNU Octave
- Python (scipy.io)
- MATLAB
Open a .mat file step by step
- Confirm the file really is a .mat. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with MATLAB or GNU Octave.
- On Mac, use MATLAB or GNU Octave.
- On Linux, try GNU Octave or Python (scipy.io).
- Still stuck? Convert the .mat to csv, which opens more widely.
Why can't I open my .mat file?
Almost always because no installed app understands MAT. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .mat at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
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.
What is the .mat file signature (magic bytes)?
A .mat file starts with the hex bytes 4D 41 54 4C 41 42 20 35 2E 30, which read as MATLAB 5.0 in ASCII. Programs identify MAT by those bytes, not by the filename, so a renamed file still gives itself away.
These are the documented signatures for MAT. For a full breakdown, see the MATLAB MAT-file file signature page.
| Hex signature | Offset | ASCII | Note |
|---|---|---|---|
| 4D 41 54 4C 41 42 20 35 2E 30 | 0 | MATLAB 5.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. How sources are ranked and what is deliberately left out is set out in the methodology.