MAT (.mat)

  • Import fully supports Versions 4 and 5 of the MAT format.
  • When appropriate, numerical data is imported as SparseArray objects.
  • Export generates MAT 4 files.
  • Background

      MATLAB MAT-files.
      Matrix data format.
      Native data format of the MATLAB numerical computation software.
      Stores numerical matrices, Boolean values, or strings.
      Binary format.
      MAT Level 4 files are compatible with MATLAB Version 4 and lower, while MAT 5 files are compatible with MATLAB Version 5 and higher versions.

    Import and 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.


    • 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.
    • 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:

    Click for copyable input

    List available Import elements

    Click for copyable input

    Import raw meta-information from this file:

    Click for copyable input

    Export a numerical matrix:

    Click for copyable input

    Scope  (2)

    Introduced in 2004
    | Updated in 2010