MAT-File format Version 5 MATLAB Array Data Element Formats The MAT-file data type mi MATRIX(14)is used to represent all types of MATLAB arrays, including Numeric arrays Character arrays Sparse arrays Structures Objects The mi MATRi X data type is a compound data type. MAT-file data elements of this type are composed of multiple subelements. The subelements can be of any other MAT-file data type, including other mi MATRiX data types Figure 5 shows a mi MATRiX data element composed of three subelements. Note how each subelement is a data element with its own tag. The value of the Number of Bytes field(96 in the figure)in the data element tag includes all the subelements Figure 5: MATLAB Array Data Element with Subelements Bytes Dat
MAT-File Format 10 Version 5 MATLAB Array Data Element Formats The MAT-file data type miMATRIX (14) is used to represent all types of MATLAB arrays, including: • Numeric arrays • Character arrays • Sparse arrays • Cell arrays • Structures • Objects The miMATRIX data type is a compound data type. MAT-file data elements of this type are composed of multiple subelements. The subelements can be of any other MAT-file data type, including other miMATRIX data types. Figure 5 shows a miMATRIX data element composed of three subelements. Note how each subelement is a data element with its own tag. The value of the Number of Bytes field (96 in the figure) in the data element tag includes all the subelements. Figure 5: MATLAB Array Data Element with Subelements Bytes 1 2 3 4 5 6 7 8 miMATRIX Data Data Data Element SubSubelement 96 Tag Tag SubElement Tag Data Tag Element 96 bytes
Version 5 MATLAB Array Data Element Formats Each mi MATRI X data element representing the different types of MATLAB arrays each has a specific set of subelements. Some of these subelements are common to all MATLAB arrays. Others subelements are unique to a particular type of array. The following sections detail the subelements for each MATLAB array type Numeric Array and character array data element Formats A MAT-file data element representing a matlab numeric array or character array is composed of four subelements and one optional subelement. Table 2 lists the subelements in the order in which they appear in the data element. The table also includes the values of the Data Type and Number of Bytes fields ou would use in the tag of each subelement. For an example, see"Examples of Numeric Array Data Elements"on page-15 Table 2: Numeric and Character Array Subelements with Tag Data Subelement Number of Bytes mi UI NT32 2*size-of-Dat a-Type (8 bytes) Dimensions Array number-of-di mensi ons*si ze-of-Dat a-Type CTo learn how to determine the number of dimensions, see"Dimensions Array Subelement on page-13) Array Name number-of-characters*si ze-of-Dat a-Type Real part (pr) Any of the numeric number-of-val ues*size-of-Data-Type ta types. Imaginary part(pi) Any of the numeric number-of-val ues*size-of-Data-Type (Optional) data types This subelement identifies the MATLAB array type(class)represented by the data element and provides other information about the array. The Array Flags subelement is common to all array type
Version 5 MATLAB Array Data Element Formats 11 Each miMATRIX data element representing the different types of MATLAB arrays each has a specific set of subelements. Some of these subelements are common to all MATLAB arrays. Others subelements are unique to a particular type of array. The following sections detail the subelements for each MATLAB array type. Numeric Array and Character Array Data Element Formats A MAT-file data element representing a MATLAB numeric array or character array is composed of four subelements and one optional subelement. Table 2 lists the subelements in the order in which they appear in the data element. The table also includes the values of the Data Type and Number of Bytes fields you would use in the tag of each subelement. For an example, see “Examples of Numeric Array Data Elements” on page -15. Array Flags Subelement This subelement identifies the MATLAB array type (class) represented by the data element and provides other information about the array. The Array Flags subelement is common to all array types. Table 2: Numeric and Character Array Subelements with Tag Data Subelement Data Type Number of Bytes Array Flags miUINT32 2*size-of-Data-Type (8 bytes) Dimensions Array miINT32 number-of-dimensions*size-of-Data-Type (To learn how to determine the number of dimensions, see “Dimensions Array Subelement” on page -13.) Array Name miINT8 number-of-characters*size-of-Data-Type Real part (pr) Any of the numeric data types. number-of-values*size-of-Data-Type Imaginary part (pi) (Optional) Any of the numeric data types. number-of-values*size-of-Data-Type
MAT-File format Figure 6 illustrates the format of the Array Flags subelement. (For sparse matrices, bytes 5 through 8 are used to store the maximum number of nonzero elements in the matrix. See"Sparse Array Data Element Format"on page-18 for more information. Figure 6: Array Flags Format Byt Undefined Flags Cl ass Un i ned Global Flags. This field contains three, single-bit flags that indicate whether the numeric data is complex, global, or logical. If the complex bit is set, the data element includes an imaginary part (pi ) If the global bit is set, MATLAB loads the data element as a global variable in the base workspace. If the logical bit is set, it indicates the array is used for logical indexing Class. This field contains a value that identifies the matlab array type(class) represented by the data element. Table 3 lists the MATLAB array types with the values you use to specify them. The table also includes symbols that are used to represent the matlab array type in the examples in this document Note The value of the Class field identifies the matlab data type. The value of the Data Type field in the data element tag identifies the data type used to store the data in the MAT-file. The MAT-file data types are listed in Table 1. The value of the Class and the Data Type fields do not need to be the same; for more information, see"Data Compression"on page-15
MAT-File Format 12 Figure 6 illustrates the format of the Array Flags subelement. (For sparse matrices, bytes 5 through 8 are used to store the maximum number of nonzero elements in the matrix. See “Sparse Array Data Element Format” on page -18 for more information.) Figure 6: Array Flags Format Flags. This field contains three, single-bit flags that indicate whether the numeric data is complex, global, or logical. If the complex bit is set, the data element includes an imaginary part (pi). If the global bit is set, MATLAB loads the data element as a global variable in the base workspace. If the logical bit is set, it indicates the array is used for logical indexing. Class. This field contains a value that identifies the MATLAB array type (class) represented by the data element. Table 3 lists the MATLAB array types with the values you use to specify them. The table also includes symbols that are used to represent the MATLAB array type in the examples in this document. Note The value of the Class field identifies the MATLAB data type. The value of the Data Type field in the data element tag identifies the data type used to store the data in the MAT-file. The MAT-file data types are listed in Table 1. The value of the Class and the Data Type fields do not need to be the same; for more information, see “Data Compression” on page -15. Undefined Bytes 1 2 3 4 5 6 7 8 Flags Class U n d e f i n e d Undefined Complex Global Logical