matreader
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.
Features
- Walks the full MATLAB v5 hierarchy (numeric matrices, structs, cells, and char arrays).
- Summary mode streams through data to report dimensions, dtype, and a short preview without loading full matrices.
- Full mode (optional) captures raw numeric values, with a configurable per-array limit to avoid blowing out memory.
- Built-in
to_ndarray()helper converts captured numeric arrays intondarray::ArrayD<f64>for downstream processing. - Command-line interface for quick inspection; library API for embedding in your own Rust projects.
Install / Build
CLI Usage
# Summaries only (default)
# Capture up to 200 elements per array, and render as ndarray
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).
Library Usage Example
use ;
Direct ndarray extraction
If you only need the numeric matrices, you can let the crate collect them for you:
use MatFile;
Notes
- Only MATLAB v5 little-endian files are supported. v7.3 (HDF5-based) files are not.
- When arrays exceed the
max_valuesthreshold in full mode, the reader falls back to summaries and marks them as truncated. - The helper script
scripts/write_sample.shruns the tool onS1_Session_1.matand captures the first 200 output lines intest.txt.