save_matfile

Contents

save_matfile#

class braintools.file.save_matfile(filename, data, verbose=False, **kwargs)[source]#

Save a dictionary of variables to a MATLAB .mat file via scipy.

This is the counterpart of load_matfile(). It is a thin, validated wrapper around scipy.io.savemat().

Parameters:
  • filename (str | PathLike) – Destination path for the .mat file.

  • 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:

None

See also

load_matfile

Load a MATLAB .mat file.

scipy.io.savemat

Underlying 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