save_matfile#
- class braintools.file.save_matfile(filename, data, verbose=False, **kwargs)[source]#
Save a dictionary of variables to a MATLAB
.matfile via scipy.This is the counterpart of
load_matfile(). It is a thin, validated wrapper aroundscipy.io.savemat().- Parameters:
filename (
str|PathLike) – Destination path for the.matfile.data (
Dict[str,Any]) – Mapping from MATLAB variable names (str) to array-like values.verbose (
bool) – If True, print saving information. Defaults to False.**kwargs – Additional keyword arguments passed to
scipy.io.savemat()(e.g.do_compression,oned_as,format).
- Raises:
TypeError – If filename is not path-like, or data is not a dict.
ValueError – If saving fails.
- Return type:
See also
load_matfileLoad a MATLAB .mat file.
scipy.io.savematUnderlying MATLAB file writer.
Examples
>>> import os >>> import tempfile >>> import numpy as np >>> from braintools.file import save_matfile >>> path = os.path.join(tempfile.mkdtemp(), 'out.mat') >>> save_matfile(path, {'x': np.arange(3), 'label': 'trial-1'}) >>> os.path.exists(path) True