Decode the contents of a MATLAB MAT-file.
var = matfiledecode(fd) var = matfiledecode(data) var = matfiledecode(..., ignoreErr)
matfiledecode(fd) reads data from file descriptor fd until the end of the file. The data must be the contents of a MATLAB-compatible MAT-file. They are made of 8-bit bytes; no text conversion must take place. The result is a structure whose fields have the name and the contents of the variables saved in the MAT-file.
Instead of a file descriptor, the data can be provided directly as the argument. In that case, the argument data must be an array, which can be read from the actual file with fread or obtained from a network connection.
Only arrays are supported (scalar, matrices, arrays of more than two dimensions, real or complex, numeric, logical or char). A second input argument can be used to specify how to handle data of unsupported types: with false (default value), unsupported types cause an error; with true, they are ignored.
fd = fopen('data.mat'); s = matfiledecode(fd); fclose(fd); s s = x: real 1x1024 y: real 1x1024
Encode the contents of a MATLAB MAT-file.
matfileencode(fd, s) matfileencode(s)
matfileencode(fd,s) writes the contents of structure s to file descriptor fd as a MATLAB-compatible MAT-file. Each field of s corresponds to a separate variable in the MAT-file. With one argument, matfileencode(s) writes to the standard output (which should be uncommon since MAT-files contain non-printable bytes).
Only arrays are supported (scalar, matrices, arrays of more than two dimensions, real or complex, numeric, logical or char).
s.a = 123; s.b = 'abc'; fd = fopen('data.mat', 'wb'); matfileencode(fd, s); fclose(fd);
Function variables can be used to save all variables:
v = variables; fd = fopen('var.mat', 'wb'); matfileencode(fd, v); fclose(fd);