Expand description
MATLAB level-4 .mat files (SciPy’s io.loadmat and io.savemat with format='4').
A level-4 file has no file header: it is a sequence of variables, each a 20-byte header of five
32-bit integers (MOPT, rows, columns, a complex flag and the name length), the NUL-terminated
name, and the column-major data (the real part, then the imaginary part when the flag is set).
MOPT = 1000 M + 100 O + 10 P + T packs the byte order M (0 little-endian IEEE, 1
big-endian IEEE), a reserved digit O = 0, the data type P (double, single, int32, int16,
uint16 or uint8) and the matrix type T (full, text or sparse). A sparse matrix is stored as
an (nnz + 1) × 3 array of 1-based row, column and value, with the matrix dimensions in its
last row (a fourth column holds the imaginary parts of a complex one).
Variables are returned as MatValue, the same type the level-5 reader produces. Reading
accepts both IEEE byte orders; VAX and Cray files are refused. Writing produces little-endian
files.
See the book entry Scientific data files.
Enums§
- MatVersion
- The version of a MAT-file, as told by its first bytes.
Functions§
- mat4_
decode - Parses a level-4 MAT-file (SciPy’s
loadmat): the variables in file order, as(name, value)pairs. Numeric matrices keep their stored type, text becomes a character array, and a sparse matrix a compressed-sparse-columnMatValue::Sparse. - mat4_
encode - Writes a level-4 MAT-file (SciPy’s
savematwithformat='4'), little-endian (seemat4_encode_big_endianfor the other byte order). Level 4 holds two-dimensional arrays of doubles, singles, 32- and 16-bit integers and bytes, text, and sparse matrices: other classes, logical arrays, cells, structures and arrays of more than two dimensions are refused. - mat4_
encode_ big_ endian - As
mat4_encode, big-endian (MOPTdigit 1): the byte order of MATLAB on 68000 and SPARC machines, read by every level-4 reader. - mat_
decode_ any - Reads a MAT-file of either level 4 or level 5, by
mat_version. - mat_
version - Tells the version of a MAT-file (SciPy’s
get_matfile_version): a level-5 file starts with a 128-byte text header ending in a version and an endian indicator; otherwise the first four bytes are tried as theMOPTof a level-4 variable in each byte order. - read_
mat4_ file - Reads a level-4 MAT-file.
- write_
mat4_ file - Writes a level-4 MAT-file.