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 a multidimensional array containing numbers, strings or Boolean values.
- Import["file.mat",elem] imports the specified element from a MAT-file.
- The import format can be specified with Import["file", "MAT"] or Import["file",{"MAT",elem,…}].
- Export["file.mat",expr] creates a MAT-file from an array of integers, doubles and complex values.
- Export["file.mat",{elem1->expr1,elem2->expr2,…},"Rules"] uses rules to specify the elements to be exported.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements

- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - 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.
- Data descriptor elements:
-
"DataFormat" variable data type "Dimensions" dimensions of the array - When appropriate, numerical data is imported as SparseArray objects.
- Meta-information element:
-
"Comments" user comments stored in the file "Labels" variable names given as a list of strings "Version" version of the MAT specification for the file
Options

- Import options:
-
"IndeterminateValues" Automatic replacement values for infinity, NaN, etc. - Use "IndeterminateValues" to provide replacement rules for different values. The following settings are supported:
-
val a fixed value val for any indeterminate value <"NaN"…,"Inf"…,"-Inf"… > specific replacements depending on the type indeterminate - Export options:
-
CompressionLevel Automatic compression level to use OverwriteTarget True whether to overwrite an existing file "Version" Automatic version of the file format to use - Using OverwriteTarget->"Append", new objects may be added to an existing file.
- Supported versions in export are "4", "5", "7.3".
- By default, export generates version "5" MAT-files. For variables larger than
bytes, a version "7.3" file is generated.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Scope (9)Survey of the scope of standard use cases
Import (2)
List available Import elements

https://wolfram.com/xid/0xl88o-53cq0j

Import a variable with label "y":

https://wolfram.com/xid/0xl88o-3cav5o

Export (7)
Export an array of numbers to a MAT-file:

https://wolfram.com/xid/0xl88o-va3x89

If no variable name is given, the default variable name "Expression1" is used:

https://wolfram.com/xid/0xl88o-le61w9

Export data with custom variable name:

https://wolfram.com/xid/0xl88o-ww4wxn


https://wolfram.com/xid/0xl88o-4ub2tz

Export multiple variables to a file. Variable names must be explicitly given:

https://wolfram.com/xid/0xl88o-r29dk8


https://wolfram.com/xid/0xl88o-qiufqr

Export a SparseArray:

https://wolfram.com/xid/0xl88o-2t4rkr


https://wolfram.com/xid/0xl88o-18f9o1


https://wolfram.com/xid/0xl88o-193mz


https://wolfram.com/xid/0xl88o-zm8o4z

Export an array of expressions of possibly different types:

https://wolfram.com/xid/0xl88o-2nf1hs


https://wolfram.com/xid/0xl88o-ijm2f3

Export an array of associations with consistent keys into a "structure" array:

https://wolfram.com/xid/0xl88o-5hwugn


https://wolfram.com/xid/0xl88o-ncdjwi


https://wolfram.com/xid/0xl88o-6j5sml

Import Elements (10)
"Comments" (1)
"Data" (2)
"DataFormat" (1)
"Dimensions" (1)
"LabeledData" (2)
Import data as a list or namedata rules, for all variables in the file:

https://wolfram.com/xid/0xl88o-5jm4r2

Create a file with two variables:

https://wolfram.com/xid/0xl88o-kbx93z

https://wolfram.com/xid/0xl88o-01ujbs

Import variables whose name matches a string pattern:

https://wolfram.com/xid/0xl88o-2hki8l

"Labels" (1)
"Summary" (1)
Export Options (14)
CompressionLevel (3)
Export a large numeric array. By default, the data will be compressed (equivalent to level 1):

https://wolfram.com/xid/0xl88o-6hyqzw


https://wolfram.com/xid/0xl88o-l84wdm

Export data with no compression:

https://wolfram.com/xid/0xl88o-6qhqq7


https://wolfram.com/xid/0xl88o-zwnhfs

Compression is not supported in MAT version 4:

https://wolfram.com/xid/0xl88o-ilnifq



https://wolfram.com/xid/0xl88o-yjdi6m

"Header" (3)
By default, an automatic header is created:

https://wolfram.com/xid/0xl88o-o6pxua


https://wolfram.com/xid/0xl88o-lat3bw

Specify a header, which is stored after the MAT version number:

https://wolfram.com/xid/0xl88o-f0o079

The header can be imported using the "Comments" element:

https://wolfram.com/xid/0xl88o-lqgzs8

The header cannot be too long:

https://wolfram.com/xid/0xl88o-4x8kmv

OverwriteTarget (3)
By default, a new file is created for each call to Export:

https://wolfram.com/xid/0xl88o-h3toce

With OverwriteTargetFalse, existing files will not be overwritten:

https://wolfram.com/xid/0xl88o-jdz52g


To append variables at the end of an existing file, use OverwriteTarget"Append":

https://wolfram.com/xid/0xl88o-u6lx27


https://wolfram.com/xid/0xl88o-z7gnz8

A variable being appended to an existing file should have a new name:

https://wolfram.com/xid/0xl88o-mr5gcx


"Version" (5)
By default, Export creates MAT-files Version 5:

https://wolfram.com/xid/0xl88o-w69xnm


https://wolfram.com/xid/0xl88o-1nik9u


https://wolfram.com/xid/0xl88o-z2ijpx


https://wolfram.com/xid/0xl88o-wu0dj7

Export data to MAT Version 7.3:

https://wolfram.com/xid/0xl88o-kcijs1


https://wolfram.com/xid/0xl88o-vg5rvf

Version can be specified either as a number or a string:

https://wolfram.com/xid/0xl88o-7z5of3


https://wolfram.com/xid/0xl88o-4d0bje

Some data types (e.g. arrays of mixed types) cannot be exported to MAT Version 4:

https://wolfram.com/xid/0xl88o-pcwqr8

