Documentation

MAT-File Versions

Overview of MAT-File Versions

MAT-files are binary MATLAB® files that store workspace variables. By default, all save operations except new file creation with the matfile function create Version 7 MAT-files. When you create new MAT-files using the matfile, the default MAT-file version is 7.3.

The maximum size of a MAT-file is imposed only by your native file system.

To identify or change the default MAT-file version, access the MAT-Files Preferences: On the Home tab, in the Environment section, click Preferences. Select MATLAB > General > MAT-Files. The preferences apply to both the save function and the Save menu options.

This table lists and compares all MAT-file versions.

VersionLoads in MATLAB VersionsSupported FeaturesCompressionMaximum Size of Each VariableValue of version argument to save functionPreference Option
Version 7.37.3 (R2006b) or later

Saving and loading parts of variables, and all Version 7 features

Yes≥ 2 GB on 64-bit computers'-v7.3'MATLAB Version 7.3 or later
(save -v7.3)
Version 77.0 (R14) or later

Unicode® character encoding, which enables file sharing between systems that use different default character encoding schemes, and all Version 6 features.

Yes2^31 bytes per variable '-v7'MATLAB Version 7 or later
(save -v7)
Version 65 (R8) or later

N-dimensional arrays, cell arrays, structure arrays, variable names longer than 19 characters, and all Version 4 features.

No2^31 bytes per variable '-v6'MATLAB Version 5 or later
(save -v6)
Version 4All

Two-dimensional double, character, and sparse arrays

No100,000,000 elements per array, and 2^31 bytes per variable'-v4'n/a

    Note:   Version 7.3 MAT-files use an HDF5 based format that requires some overhead storage to describe the contents of the file. For cell arrays, structure arrays, or other containers that can store heterogeneous data types, Version 7.3 MAT-files are sometimes larger than Version 7 MAT-files.

Save to Nondefault MAT-File Version

Save to a MAT-file version other than the default version when you want to:

  • Allow access to the file using earlier versions of MATLAB.

  • Take advantage of Version 7.3 MAT-file features.

  • Reduce the time required to load and save some files by storing uncompressed data.

  • Reduce the size of some files by storing compressed data.

To save to a MAT-file version other than the default version, specify a value of version as the last input argument to the save function. For example, to create a Version 6 MAT-file named myfile.mat, type:

save('myfile.mat','-v6')

Data Compression

Beginning with Version 7, MATLAB compresses data when writing to MAT-files to save storage space. Data compression and decompression slow down all save operations and some load operations. In most cases, the reduction in file size is worth the additional time spent.

In fact, loading compressed data is sometimes faster than loading uncompressed data. For example, consider a block of data in a numeric array saved to both a 10 MB compressed file and a 100 MB uncompressed file. Loading the first 10 MB takes the same amount of time for each file. Loading the remaining 90 MB from the uncompressed file takes nine times as long as loading the first 10 MB. Completing the load of the compressed file requires only the relatively short time to decompress the data.

However, the benefits of data compression are negligible in the following cases:

  • The amount of data in each item is small relative to the complexity of its container. For example, simple numeric arrays take less time to compress and uncompress than cell or structure arrays of the same size. Compressing arrays that result in an uncompressed file size of less than 3 MB offers limited benefit, unless you are transferring data over a network.

  • The data is random, with no repeated patterns or consistent values.

Accelerate Save and Load Operations for Version 7.3 MAT-Files

Version 7.3 MAT-files use an HDF5-based format that stores data in compressed chunks. The time required to load part of a variable from a Version 7.3 MAT-file depends on how that data is stored across one or more chunks. Each chunk that contains any portion of the data you want to load must be fully uncompressed to access the data. Rechunking your data can improve the performance of the load operation. To rechunk data, use the HDF5 command-line tools, which are part of the HDF5 distribution.

See Also

|

Was this topic helpful?