@docfiller<EOL>def savemat(file_name, mdict,<EOL>appendmat=True,<EOL>format='<STR_LIT:5>',<EOL>long_field_names=False,<EOL>do_compression=False,<EOL>oned_as='<STR_LIT>'):
file_is_string = isinstance(file_name, string_types)<EOL>if file_is_string:<EOL><INDENT>if appendmat and file_name[-<NUM_LIT:4>:] != "<STR_LIT>":<EOL><INDENT>file_name = file_name + "<STR_LIT>"<EOL><DEDENT>file_stream = open(file_name, '<STR_LIT:wb>')<EOL><DEDENT>else:<EOL><INDENT>if not hasattr(file_name, '<STR_LIT>'):<EOL><INDENT>raise IOError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>file_stream = file_name<EOL><DEDENT>if format == '<STR_LIT:4>':<EOL><INDENT>if long_field_names:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>MW = MatFile4Writer(file_stream, oned_as)<EOL><DEDENT>elif format == '<STR_LIT:5>':<EOL><INDENT>MW = MatFile5Writer(file_stream,<EOL>do_compression=do_compression,<EOL>unicode_strings=True,<EOL>long_field_names=long_field_names,<EOL>oned_as=oned_as)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>MW.put_variables(mdict)<EOL>if file_is_string:<EOL><INDENT>file_stream.close()<EOL><DEDENT>
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.

See also
--------
mio4.MatFile4Writer
mio5.MatFile5Writer