loads some variables from an Octave or a Matlab MAT binary or ASCII data file
loadmatfile(filename) loadmatfile(filename, var1, var2, ...) loadmatfile(format, filename, ...) loadmatfile(filename, format, ...) loadmatfile(filename, var1, var2, .., format) struc = loadmatfile(.., "-toStruct")
character string containing the path of the file.
Explicit file format. If it is not given, loadmatfile() tries to determine the format from the file header, etc. If the data format is still unknown and the file name has the ".mat" extension, the file is considered to be a Matlab binary data file. Available explicit formats are:
"-mat" | Matlab binary file. |
---|---|
"-octave" | Octave native text file. |
"-ascii" | ASCII file as got from Matlab or Octave with the
save -ascii option. |
The format
can be provided anywhere in the list of inputs.
Strings. Names of the variables that must be loaded from the file.
If no name is provided, all the variables stored in the file are loaded.
Ignored if -ascii
is used.
Input keyword used if the read variables must be returned as fields of an output structure, instead of directly into the calling environment.
Structure whos fields are the names of variables read from the file, with their respective values.
loadmatfile(filename) reads all the variables names and values stored in the given Matlab or Octave data file, and returns them in the calling environment.
struc = loadmatfile(filename, "-toStruct") does the
same, but provides the read variables through the struc
output
structure. Any read variable varname = value can then be accessed
through struc.varname
. Only struc
is returned
to the calling environment.
![]() | This option avoids unexpectedly overwriting a variable existing in the calling
environment with an homonymous variable from the file. |
loadmatfile(filename, .., var2, var2, ..)
reads from the file only variables whose names var1, var2, ..
are provided.
loadmatfile(filename, ..,"-mat") forces the file to be read as a Matlab binary data file.
loadmatfile(filename, ..,"-octave") forces the file to be read as an Octave native text data file (default Octave format).
loadmatfile(filename, ..,"-ascii") forces the file to be read as a Matlab ASCII data file (very poor format). In this case, only one variable is read and returned. Its name is set to the basename of the file (with forbidden characters removed).
In all ways, the Octave or Matlab data types are converted into the Scilab equivalents.
About native Octave 5.1 text data files:
From a .mat Matlab file:
A = grand(4, 6, "uin", 0, 10); B = sprand(10,12,0.1); filename = TMPDIR + "/test_matfile.mat"; savematfile(filename, 'A', 'B', '-v6'); clear A B loadmatfile(filename); disp(A) disp(B) | ![]() | ![]() |
From an Octave file:
filename = pathconvert("SCI/modules/matio/tests/unit_tests/octave/octave_struct.txt"); // Read all variables, with automatic format detection: clear ste ste2 sts stm stm2 r = loadmatfile(filename,"-toStruct") isdef(["ste" "sts"]) // Read only a subset of stored variables: r = loadmatfile(filename,"-toStruct", "ste", "sts") isdef(["ste" "sts"]) // Returns the data in the calling environment: ste = "This will be overwritten" loadmatfile(filename,"ste", "sts"); ste, sts | ![]() | ![]() |
--> clear ste ste2 sts stm stm2 --> r = loadmatfile(filename,"-toStruct") r = ste: [0x0 struct] with no field ste2: [0x0 struct] with no field sts: [1x1 struct] with fields: r = [3.1415927,2.7182818,%i] b = %f t = ["abc","ABC"] stm: [2x2 struct] with fields: r b stm2: [2x2 struct] with fields: r b n --> isdef(["ste" "sts"]) ans = F F --> // Read only a subset of stored variables: --> r = loadmatfile(filename,"-toStruct", "ste", "sts") r = ste: [0x0 struct] with no field sts: [1x1 struct] with fields: r = [3.1415927,2.7182818,%i] b = %f t = ["abc","ABC"] --> isdef(["ste" "sts"]) ans = F F --> // Returns the data in the calling environment: --> ste = "This will be overwritten" ste = This will be overwritten --> loadmatfile(filename,"ste", "sts"); --> ste, sts ste = 0x0 struct with no field sts = r = [3.1415927,2.7182818,%i] b = %f t = ["abc","ABC"]
The binary mode of this function is based on the MATIO library (
http://sourceforge.net/projects/matio/
).
Version | Description |
6.1.0 |
|