MATLAB The Language of Technical Computing Computation Visualization Programming MAT-File Format The MathWorks Version 5
Computation Visualization Programming MAT-File Format Version 5 MATLABÆ The Language of Technical Computing
MAT-File format Introduction MAT-File formats Version 5 MAT-File format MAT-File header format 22356 Data element format Version 5 MATLAB Array Data Element Formats 10 Numeric Array and Character Array Data Element Formats.. 11 Sparse array Data Element Format Cell Array Data Element Format .22 Structure mat-file data element format MATLAB Object MAT-File Data Element Format Version 4 MAT-File format
MAT-File Format Introduction . . . . . . . . . . . . . . . . . . . . . 2 MAT-File Formats . . . . . . . . . . . . . . . . . . . 2 Version 5 MAT-File Format . . . . . . . . . . . . . . 3 MAT-File Header Format . . . . . . . . . . . . . . . . 5 Data Element Format . . . . . . . . . . . . . . . . . . 6 Version 5 MATLAB Array Data Element Formats . . . .10 Numeric Array and Character Array Data Element Formats . .11 Sparse Array Data Element Format . . . . . . . . . . . .18 Cell Array Data Element Format . . . . . . . . . . . . .22 Structure MAT-File Data Element Format . . . . . . . . .25 MATLAB Object MAT-File Data Element Format . . . . . .29 Version 4 MAT-File Format . . . . . . . . . . . . . .32
MAT-File format Introduction This document describes the internal format of matlab version 5 and Version 4 MAT-files. A MAT-file stores data in binary (not human-readable form. In MATLAB, you create MAT-files by using the save command, which writes the arrays currently in memory to a file as a continuous byte stream. By convention this file has the filename extension. mat thus the name mat-file The l oad command reads the arrays from a MAT-file into the MATLAB Most matlab users do not need to know the internal format of a mat-file ven users who must read and write MAT-files from C and Fortran programs do not need to know the MAT-file format if they use the MATLAB Application Program Interface(API). This API shields users from dependence on the details of the mat-file format However, if you need to read or write MAT-files on a system for which the MATLAB API library is not supported, you must write your own read and write outines. The MATLAB API is only available for platforms on which MATLAB is supported. This document provides the details about the MAT-file format you will need to read and write MAT-files on these systems Note Whenever possible, The MathWorks strongly advises you to use the MAT-file APi routines to read and write MAT-files. Any code you write that depends on the MAT-file format will very likely need to be rewritten when the format changes in future releases MAT-File Formats This document describes both the matlab version 5 and Version 4 MAT-file formats. The MATLAB Version 5 MAT-file format supports all the matlaB V5 array types, including multidimensional numeric arrays, character arrays sparse arrays, cell arrays, structures, and objects. Version 5 MAT-File Format"on page-3 describes this format The MATLAB Version 4 MAT-file format is a simpler format but it only supports two-dimensional matrices and character strings. "Version 4 MAT-File Format"on page -32 describes this format
MAT-File Format 2 Introduction This document describes the internal format of MATLAB ® Version 5 and Version 4 MAT-files. A MAT-file stores data in binary (not human-readable) form. In MATLAB, you create MAT-files by using the save command, which writes the arrays currently in memory to a file as a continuous byte stream. By convention, this file has the filename extension .mat; thus the name MAT-file. The load command reads the arrays from a MAT-file into the MATLAB workspace. Most MATLAB users do not need to know the internal format of a MAT-file. Even users who must read and write MAT-files from C and Fortran programs do not need to know the MAT-file format if they use the MATLAB Application Program Interface (API). This API shields users from dependence on the details of the MAT-file format. However, if you need to read or write MAT-files on a system for which the MATLAB API library is not supported, you must write your own read and write routines. The MATLAB API is only available for platforms on which MATLAB is supported. This document provides the details about the MAT-file format you will need to read and write MAT-files on these systems. Note Whenever possible, The MathWorks strongly advises you to use the MAT-file API routines to read and write MAT-files. Any code you write that depends on the MAT-file format will very likely need to be rewritten when the format changes in future releases. MAT-File Formats This document describes both the MATLAB Version 5 and Version 4 MAT-file formats. The MATLAB Version 5 MAT-file format supports all the MATLAB V5 array types, including multidimensional numeric arrays, character arrays, sparse arrays, cell arrays, structures, and objects. “Version 5 MAT-File Format” on page -3 describes this format. The MATLAB Version 4 MAT-file format is a simpler format but it only supports two-dimensional matrices and character strings. “Version 4 MAT-File Format” on page -32 describes this format
Version 5 mat-file format Version 5 mAt-file format In MATLAB Version 5, a MAT-file is made up of a 128-byte header followed by ne or more data elements. Each data element is composed of an 8-byte tag followed by the data in the element. The tag specifies the number of bytes in the data element and how these bytes should be interpreted; that is, should the bytes be read as 16-bit values, 32-bit values, floating point values or some other data type By using tags, the Version 5 MAT-file format provides quick access to individual data elements within a MAT-file. You can move through a MaT-file by finding a tag and then skipping ahead the specified number of bytes until the next tag MATLAB Version 5 MAT-File Format"on page-4 graphically illustrates this MAT-file format. The sections that follow provide more details about these MAT-file elements
Version 5 MAT-File Format 3 Version 5 MAT-File Format In MATLAB Version 5, a MAT-file is made up of a 128-byte header followed by one or more data elements. Each data element is composed of an 8-byte tag followed by the data in the element. The tag specifies the number of bytes in the data element and how these bytes should be interpreted; that is, should the bytes be read as 16-bit values, 32-bit values, floating point values or some other data type. By using tags, the Version 5 MAT-file format provides quick access to individual data elements within a MAT-file. You can move through a MAT-file by finding a tag and then skipping ahead the specified number of bytes until the next tag. “MATLAB Version 5 MAT-File Format” on page -4 graphically illustrates this MAT-file format. The sections that follow provide more details about these MAT-file elements
MAT-File format Figure 1: MATLAB Version 5 MAT-File Format tea Descriptive text(124 bytes) Version Endian Indicator Data Type Number of Bytes Data(variable size) or subelements Data t Number of Bytes Data(variable size) or subelements m鸟口m93品 umber of Bytes Data(variable size) or subelements Repeat Tagged Data Elements Until End-of-File
MAT-File Format 4 Figure 1: MATLAB Version 5 MAT-File Format Bytes 1 2 3 4 5 6 7 8 MAT-File Header (128 bytes) Descriptive text (124 bytes) Version Endian Indicator Data Type Number of Bytes Data (variable size) or subelements Data Type Number of Bytes Data Element Data Element Repeat Tagged Data Elements Until End-of-File Data Type Number of Bytes Data Element Data (variable size) or subelements Data (variable size) or subelements