THE FILE FIELD GUIDE
.mat

MATLAB Data

Data & Science

MAT stores MATLAB variables in version-dependent formats; only Version 7.3 is HDF5-based. Files may contain objects, not just arrays. MathWorks warns that load may execute code when initializing variables in untrusted MAT files.

What it is used for
Storage of MATLAB arrays, structures and variables
What the file contains
Binary data
All sections, questions and sources

Content reviewed: · Editor:Kai

Opening steps

Choose your environment or purpose to see its steps.

Inspect variables in a trusted MAT file

Verify provenance and work on a copy.

  1. Use supported variable inspection such as whos -file.
  2. Inspect names, classes, dimensions and estimated memory.
  3. Load only required variables into a separate structure.
Read a supported version in Python

7.3 differs from earlier MAT versions.

  1. Identify file version and variable types.
  2. Use supported SciPy loading or a suitable 7.3/HDF5 workflow.
  3. Compare array shapes, strings and cell/struct handling.
Access a large array partially

Efficient partial access has file-version requirements.

  1. Inspect supported version and variable size.
  2. Use matfile or another supported partial-reader workflow.
  3. Record axes/slice bounds and verify results.

Menu labels and support vary by app, OS and version. Preserve the original before making changes.

Troubleshooting by symptom

  • Other reader fails: check version, cells, structures and custom classes.
  • Too large: review per-variable size and supported partial loading.
  • Workspace overwritten: preserve work and load into separate variables/structures.
  • SciPy rejects 7.3: inspect loadmat’s version/HDF5 limitation.
  • Variables replaced: load into a separate structure.
  • Out of memory: inspect dimensions/version and supported partial access.

Numeric MAT variables → CSV / NPY / HDF5

  1. Select numeric variables in a trusted environment; record shape/units.
  2. Export suitably and compare ordering, complex values, precision and nulls.
  3. Compare dimensions, axes, cells/structures and required variables after migration.

CSV cannot retain arbitrary dimensions/objects; renaming MAT to H5 does not create Version 7.3.

Record file version and variable classes

Numeric arrays, cells, structures and objects have different interchange requirements.

Generic HDF5 access does not guarantee complete MATLAB-object reconstruction.

Source for these steps:MathWorks · MAT File Versions / MathWorks · load — Load variables from file / MathWorks · MatFile — Access variables without loading the entire file / SciPy Project · scipy.io.loadmat

Validate partial-array boundaries

Inspect partial-access requirements and record variable/axis selection.

Define handling for multidimensional data before CSV export and retain dimensions/types.

Source for these steps:MathWorks · MAT File Versions / MathWorks · load — Load variables from file / MathWorks · MatFile — Access variables without loading the entire file / SciPy Project · scipy.io.loadmat

Related-format differences

Related-format differences
FormatMain roleWhat to check
MAT prior to 7.3Earlier MAT storageCompatible MAT reader
MAT 7.3HDF5-based storageMAT structures/partial access
CSVText table outputAxes/types need documentation

Handling and security

Do not load unknown MAT merely to inspect it; establish trusted provenance/version and retain originals.

Questions and answers

Is all MAT HDF5?

Version 7.3 uses HDF5; older formats differ.

Is load inherently safe?

Variable initialization may execute code.

Does a plot preserve the data?

Retain numeric arrays separately from visualization images.

Why can array shapes change in Python?

Inspect dimension-squeezing and cell/struct options and compare original axes.

Must I export an entire large array to CSV?

Select required slices with a compatible partial reader and document dimensions/selection.

Format facts: name, steward and MIME type
Formal name
MATLAB MAT-file (multiple versions)
Steward / specification
MathWorks
MIME type
Depends on the producer or server; an extension alone does not establish a MIME type.

Primary and official sources