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.

See also

load_matfile

Load a MATLAB .mat file.

scipy.io.savemat

Underlying MATLAB file writer.

Return type:

None

Examples

>>> import numpy as np
>>> save_matfile('out.mat', {'x': np.arange(3), 'label': 'trial-1'})