Skip to main content

Module matlab4

Module matlab4 

Source
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-column MatValue::Sparse.
mat4_encode
Writes a level-4 MAT-file (SciPy’s savemat with format='4'), little-endian (see mat4_encode_big_endian for 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 (MOPT digit 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 the MOPT of 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.