| Crates.io | matfile |
| lib.rs | matfile |
| version | 0.5.0 |
| created_at | 2019-04-04 21:00:32.840242+00 |
| updated_at | 2024-10-20 19:31:24.70017+00 |
| description | Matfile is a library for reading and writing Matlab ".mat" data files. |
| homepage | |
| repository | https://github.com/dthul/matfile |
| max_upload_size | |
| id | 125877 |
| size | 73,424 |
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.
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 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 supportHelpers 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.
First, bring the TryInto trait into scope:
use std::convert::TryInto;
Converting a matfile array mf_arr to a dynamic dimension ndarray array
nd_arr:
let nd_arr: ndarray::ArrayD<f64> = mf_arr.try_into()?;
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()?;