| Crates.io | matreader |
| lib.rs | matreader |
| version | 0.1.0 |
| created_at | 2025-10-18 00:00:56.113525+00 |
| updated_at | 2025-10-18 00:00:56.113525+00 |
| description | Parser and CLI for MATLAB v5 .mat files with ndarray support |
| homepage | https://github.com/SerpensBCI/matreader |
| repository | https://github.com/SerpensBCI/matreader |
| max_upload_size | |
| id | 1888610 |
| size | 52,865 |
matreader is both a Rust crate and a CLI tool for inspecting MATLAB v5 .mat files that contain EEG data (or any combination of numeric arrays, structs, cells, and strings). It was written to work with large EEG datasets that nest trials inside cell arrays and store channel metadata in structs.
to_ndarray() helper converts captured numeric arrays into ndarray::ArrayD<f64> for downstream processing.cargo build
# Summaries only (default)
cargo run -- S1_Session_1.mat
# Capture up to 200 elements per array, and render as ndarray
cargo run -- --mode full --max-values 200 --ndarray S1_Session_1.mat
Output is a tree of variables. Each numeric entry prints dimensions, dtype, a handful of leading values, and either the raw numbers or an ndarray dump (if requested).
use matreader::{MatFile, MatValue, ParseMode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = std::fs::File::open("S1_Session_1.mat")?;
let mat = MatFile::parse_reader(file, ParseMode::Full { max_values: 10_000 })?;
for value in mat.values {
if let MatValue::Numeric(summary) = value {
if let Some(array) = summary.to_ndarray() {
println!("{} has ndarray shape {:?}", summary.name, array.shape());
}
}
}
Ok(())
}
If you only need the numeric matrices, you can let the crate collect them for you:
use matreader::MatFile;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = std::fs::File::open("S1_Session_1.mat")?;
let arrays = MatFile::parse_ndarrays(file, 10_000)?;
println!("loaded {} arrays", arrays.len());
for array in arrays {
println!("shape: {:?}", array.shape());
}
Ok(())
}
max_values threshold in full mode, the reader falls back to summaries and marks them as truncated.scripts/write_sample.sh runs the tool on S1_Session_1.mat and captures the first 200 output lines in test.txt.