Methods list

Methods usage

MAT.matopenFunction
matopen(filename [, mode]; compress = false, table = MatlabTable) -> handle
matopen(f::Function, filename [, mode]; compress = false, table = MatlabTable) -> f(handle)

Mode defaults to "r" for read. It can also be "w" for write, or "r+" for read or write without creation or truncation.

Compression on reading is detected/handled automatically; the compress keyword argument only affects write operations.

Use with read, write, close, keys, and haskey.

Optional keyword argument is the table type, for automatic conversion of Matlab tables. Note that Matlab tables may contain non-vector colums which cannot always be converted to a Julia table, like DataFrame.

Example

using MAT, DataFrames
filepath = abspath(pkgdir(MAT), "./test/v7.3/struct_table_datetime.mat")
fid = matopen(filepath; table = DataFrame)
keys(fid)

# outputs

1-element Vector{String}:
 "s"

Now you can read any of the keys

s = read(fid, "s")
close(fid)
s

# outputs

Dict{String, Any} with 2 entries:
  "testDatetime" => DateTime("2019-12-02T16:42:49.634")
  "testTable"    => 3×5 DataFrame…
source
MAT.matreadMethod
matread(filename; table = MatlabTable) -> Dict

Return a dictionary of all the variables and values in a Matlab file, opening and closing it automatically.

Optionally provide the table type to convert Matlab tables into. Default uses a simple MatlabTable type.

Example

using MAT, DataFrames
filepath = abspath(pkgdir(MAT), "./test/v7.3/struct_table_datetime.mat")
vars = matread(filepath; table = DataFrame)
vars["s"]["testTable"]

# outputs

3×5 DataFrame
 Row │ FlightNum  Customer  Date                 Rating  Comment
     │ Float64    String    DateTime             String  String
─────┼─────────────────────────────────────────────────────────────────────────────────────
   1 │    1261.0  Jones     2016-12-20T00:00:00  Good    Flight left on time, not crowded
   2 │     547.0  Brown     2016-12-21T00:00:00  Poor    Late departure, ran out of dinne…
   3 │    3489.0  Smith     2016-12-22T00:00:00  Fair    Late, but only by half an hour. …
source
MAT.matwriteMethod
matwrite(filename, d::Dict; compress::Bool = false, version::String = "v7.3")

Write a dictionary containing variable names as keys and values as values to a Matlab file, opening and closing it automatically.

source
MAT.MAT_types.MatlabClassObjectType
MatlabClassObject(
    d::Dict{String, Any},
    class::String,
) <: AbstractDict{String, Any}

Type to store old class objects. Inside MATLAB a class named "TestClassOld" would be defined within @TestClassOld folders.

If you want to write these objects you have to make sure the keys in the Dict match the class defined properties/fields.

source
MAT.MAT_types.MatlabOpaqueType
MatlabOpaque(
    d::Dict{String, Any},
    class::String,
) <: AbstractDict{String, Any}

Type to store opaque class objects. These are the 'modern' Matlab classes, different from the old MatlabClassObject types.

source
MAT.MAT_types.MatlabStructArrayType
MatlabStructArray{N}(
    names::Vector{String},
    values::Vector{Array{Any,N}},
    class::String = "",
)

Data structure to store matlab struct arrays, which stores the field names separate from the field values. The field values are stored as columns of Array{Any,N} per Matlab field, which is how MAT files store these structures.

These are distinct from cell arrays of structs, which are handled as in MAT.jl as Array{Any,N} with Dict{String,Any} inside, for example Any[Dict("x"=>1), Dict("x"=>2)].

Old class object arrays can be handled by providing a non-empty class name.

Example

using MAT

s_arr = MatlabStructArray(["a", "b"], [[1, 2],["foo", 5]])

# write-read
matwrite("matfile.mat", Dict{String,Any}("struct_array" => s_arr))
read_s_arr = matread("matfile.mat")["struct_array"]

# convert to Dict Array
dict_array = Array{Dict{String,Any}}(s_arr)

# convert to Dict (with arrays as fields)
dict = Dict{String,Any}(s_arr)
source