[ SciPy v1.12.0 Manual  ](../../index.html)

  * [ Installing ](https://scipy.org/install/)
  * [ User Guide ](../../tutorial/index.html)
  * [ API reference ](../index.html)
  * [ Building from source ](../../building/index.html)
  * [ Development ](../../dev/index.html)
  * [ Release notes ](../../release.html)

__ __ __

1.12.0

  * [ __ GitHub  ](https://github.com/scipy/scipy "GitHub")
  * [ __ Twitter  ](https://twitter.com/SciPy_team "Twitter")

__

  * [ scipy ](../main_namespace.html)
  * [ scipy.cluster ](../cluster.html)
  * [ scipy.constants ](../constants.html)
  * [ scipy.datasets ](../datasets.html)
  * [ scipy.fft ](../fft.html)
  * [ scipy.fftpack ](../fftpack.html)
  * [ scipy.integrate ](../integrate.html)
  * [ scipy.interpolate ](../interpolate.html)
  * [ scipy.io ](../io.html)
  * [ scipy.linalg ](../linalg.html)
  * [ scipy.misc ](../misc.html)
  * [ scipy.ndimage ](../ndimage.html)
  * [ scipy.odr ](../odr.html)
  * [ scipy.optimize ](../optimize.html)
  * [ scipy.signal ](../signal.html)
  * [ scipy.sparse ](../sparse.html)
  * [ scipy.spatial ](../spatial.html)
  * [ scipy.special ](../special.html)
  * [ scipy.stats ](../stats.html)

__ On this page

  * ` savemat  `

#  scipy.io.savemat  #

scipy.io.  savemat  (  _ file_name  _ , _ mdict  _ , _ appendmat  =  True  _ ,
_ format  =  '5'  _ , _ long_field_names  =  False  _ , _ do_compression  =
False  _ , _ oned_as  =  'row'  _ )  [ [source]
](https://github.com/scipy/scipy/blob/v1.12.0/scipy/io/matlab/_mio.py#L237-L301)
#

    

Save a dictionary of names and arrays into a MATLAB-style .mat file.

This saves the array objects in the given dictionary to a MATLAB- style .mat
file.

Parameters  :

    

**file_name** str or file-like object

    

Name of the .mat file (.mat extension not needed if ` appendmat  ==  True  `
). Can also pass open file_like object.

**mdict** dict

    

Dictionary from which to save matfile variables.

**appendmat** bool, optional

    

True (the default) to append the .mat extension to the end of the given
filename, if not already present.

**format** {â5â, â4â}, string, optional

    

â5â (the default) for MATLAB 5 and up (to 7.2), â4â for MATLAB 4 .mat
files.

**long_field_names** bool, optional

    

False (the default) - maximum field name length in a structure is 31
characters which is the documented maximum length. True - maximum field name
length in a structure is 63 characters which works for MATLAB 7.6+.

**do_compression** bool, optional

    

Whether or not to compress matrices on write. Default is False.

**oned_as** {ârowâ, âcolumnâ}, optional

    

If âcolumnâ, write 1-D NumPy arrays as column vectors. If ârowâ, write
1-D NumPy arrays as row vectors.

Examples

    
    
    >>> from scipy.io import savemat
    >>> import numpy as np
    >>> a = np.arange(20)
    >>> mdic = {"a": a, "label": "experiment"}
    >>> mdic
    {'a': array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19]),
    'label': 'experiment'}
    >>> savemat("matlab_matrix.mat", mdic)
    

[ __ previous  scipy.io.loadmat  ](scipy.io.loadmat.html "previous page") [
next  scipy.io.whosmat  __ ](scipy.io.whosmat.html "next page")

© Copyright 2008-2024, The SciPy community.  

Created using [ Sphinx ](http://sphinx-doc.org/) 7.2.6.