MAT (.mat)
- Import fully supports MAT Version 7.3 and lower.
- Export by default generates Version 5.0 or 7.3 MAT-files, depending on the file size.
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)
Scope (8)
Import (1)
List available Import elements
Export (7)
Export an array of numbers to a MAT-file:
If no variable name is given, the default variable name "Expression1" is used:
Export data with custom variable name:
Export multiple variables to a file. Variable names must be explicitly given:
Export a SparseArray:
Export an array of expressions of possibly different types:
Export an array of associations with consistent keys into a "structure" array:
Import Elements (8)
"Comments" (1)
"LabeledData" (1)
"Summary" (1)
Export Options (14)
CompressionLevel (3)
"Header" (3)
OverwriteTarget (3)
By default, a new file is created for each call to Export:
With OverwriteTargetFalse, existing files will not be overwritten:
To append variables at the end of an existing file, use OverwriteTarget"Append":
A variable being appended to an existing file should have a new name:
"Version" (5)
By default, Export creates MAT-files Version 5:
Export data to MAT Version 7.3:
Version can be specified either as a number or a string:
Some data types (e.g. arrays of mixed types) cannot be exported to MAT Version 4: