MAT (.mat)

Background & Context

    • MATLAB MAT-files.
    • Matrix data format.
    • Native data format of the MATLAB numerical computation software.
    • Stores numerical matrices, Boolean values, or strings.
    • Also stores sparse arrays, nested structures and more.
    • Binary format.
    • Version 7.3 of MAT files uses HDF5.

Import & Export

  • Import["file.mat"] imports a MAT-file, returning an array.
  • Export["file.mat",expr] exports any numeric array to a MAT-file.
  • Import["file.mat"] returns a multidimensional array containing numbers, strings, or Boolean values.
  • Export["file.mat",expr] creates a MAT-file from an array of integers or doubles.
  • Import["file.mat",elem] imports the specified element from a MAT-file.
  • Import["file.mat",{elem,suba,subb,}] imports a subelement.
  • Import["file.mat",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file", "MAT"] or Import["file",{"MAT",elem,}].
  • Export["file.mat",expr, elem] creates a MAT-file by treating expr as specifying element elem.
  • Export["file.mat",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.mat",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.mat",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the MAT format.

Import Elements

  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation element:
  • "Data"numerical or textual data given as a multidimensional array
    "LabeledData"data given as a list of rules
  • Import and Export use the "Data" element by default.
  • When appropriate, numerical data is imported as SparseArray objects.
  • Meta-information element:
  • "Comments"user comments stored in the file
    "Labels"dataset names given as a list of strings


open allclose all

Basic Examples  (4)

This imports a simple MAT-file:

List available Import elements

Import raw meta-information from this file:

Export a numerical matrix:

Scope  (2)

Export a few named datasets and import the resulting file:

Export a named dataset using element specifications: