Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function
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
formatcan be provided anywhere in the list of inputs.
- var1, var2
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
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
structure. Any read variable varname = value can then be accessed
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, ..
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:
- Supported input data types: dense and sparse booleans, signed and unsigned encoded integers (from int8 to uint64), real and complex numbers (including Inf, NaN and NA special values) in sparse and dense encodings, strings, arrays of cells of strings, any cell array or hyperarray of any dimension, scalar or array of structures.
- NA values are converted into NaN.
- The mantissa of single precision real and complex numbers is truncated to their 8 most significant figures.
- Any cells array of scalar strings is automatically converted into a regular Scilab array of strings.
- In any input column of strings, appended padding spaces are left as is, without being trimmed.
- In strings, ascii(13) characters are read as ascii(10).
- Cells and structures must contain only supported input data types. Otherwise, an error occurs.
- Nested containers (cells, structures) are supported.
- Known limitation: int64 or uint64 integers bigger than 253 can't be read properly (loss of precision).
From a .mat Matlab file:
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"]
- load — Loads some archived variables, a saved graphic figure, a library of functions
- savematfile — Matlab MATファイル (バイナリまたは ASCII)を書き込む
- save — Saves some chosen variables in a binary data file
- mfile2sci — Matlab M-file to Scilab conversion function
- matfile2sci — converts a Matlab 5 MAT-file into a Scilab binary file
The binary mode of this function is based on the MATIO library (
|Report an issue|
|<< Matlab binary files I/O||Matlab binary files I/O||matfile2sci >>|