#file-reader #reader-writer #matlab #mat #data-file #file-writer #file

matfile

Matfile is a library for reading and writing Matlab ".mat" data files

8 releases (4 breaking)

0.5.0 Oct 20, 2024
0.4.1 Jan 20, 2024
0.4.0 Apr 22, 2023
0.3.1 Jun 26, 2021
0.1.0 Apr 4, 2019

#275 in Parser implementations

Download history 41/week @ 2024-08-02 7/week @ 2024-08-09 2/week @ 2024-08-16 10/week @ 2024-08-23 9/week @ 2024-08-30 8/week @ 2024-09-06 19/week @ 2024-09-13 53/week @ 2024-09-20 33/week @ 2024-09-27 16/week @ 2024-10-04 52/week @ 2024-10-11 236/week @ 2024-10-18 48/week @ 2024-10-25 26/week @ 2024-11-01 15/week @ 2024-11-08 7/week @ 2024-11-15

105 downloads per month
Used in 4 crates

MIT license

63KB
1.5K SLoC

Matfile

LICENSE Build Status Docs Crates.io Version Dependency Status

Matfile is a library for reading (and in the future writing) Matlab ".mat" files.

Please note: This library is still alpha quality software and only implements a subset of the features supported by .mat files.

Feature Status

Matfile currently allows you to load numeric arrays from .mat files (all floating point and integer types, including complex numbers). All other types are currently ignored.

  • Loading .mat files
    • Numeric arrays
    • Cell arrays
    • Structure arrays
    • Object arrays
    • Character arrays
    • Sparse arrays
  • Writing .mat files

Examples

Loading a .mat file from disk and accessing one of its arrays by name:

let file = std::fs::File::open("data.mat")?;
let mat_file = matfile::MatFile::parse(file)?;
let pos = mat_file.find_by_name("pos");
println!("{:#?}", pos);

Might output something like:

Some(
    Array {
        name: "pos",
        size: [
            2,
            3
        ],
        data: Double {
            real: [
                -5.0,
                8.0,
                6.0,
                9.0,
                7.0,
                10.0
            ],
            imag: None
        }
    }
)

Note that data is stored in column-major format. For higher dimensions that means that the first dimension has the fastest varying index.

ndarray support

Helpers for converting between matfile::Array and ndarray::Array can be enabled with the ndarray feature:

[dependencies]
matfile = { version = "0.5", features = ["ndarray"] }

While matfile arrays abstract over the underlying data type, ndarray arrays are parameterized by a concrete data type. Thus the conversions provided are fallible in case the data types are not compatible.

Examples

First, bring the TryInto trait into scope:

use std::convert::TryInto;

Dynamically dimensioned arrays

Converting a matfile array mf_arr to a dynamic dimension ndarray array nd_arr:

let nd_arr: ndarray::ArrayD<f64> = mf_arr.try_into()?;

Statically dimensioned arrays

Converting a matfile array mf_arr to a static dimension ndarray array nd_arr:

let nd_arr: ndarray::Array2<num_complex::Complex<f32>> = mf_arr.try_into()?;

Dependencies

~3.5–4.5MB
~78K SLoC