def METHOD_NAME(self, obj):
    """Write a weights object to the opened MATLAB ``.mat`` file.
    Parameters
    ----------
    obj : libpysal.weights.W
        A PySAL `W` object.
    Raises
    ------
    TypeError
        Raised when the input ``obj`` is not a PySAL `W`.
    Examples
    --------
    >>> import tempfile, libpysal, os
    >>> testfile = libpysal.io.open(
    ...     libpysal.examples.get_path('spat-sym-us.mat'), 'r'
    ... )
    >>> w = testfile.read()
    Create a temporary file for this example.
    >>> f = tempfile.NamedTemporaryFile(suffix='.mat')
    Reassign to a new variable.
    >>> fname = f.name
    Close the temporary named file.
    >>> f.close()
    Open the new file in write mode.
    >>> o = libpysal.io.open(fname, 'w')
    Write the weights object into the open file.
    >>> o.write(w)
    >>> o.close()
    Read in the newly created ``.mat`` file.
    >>> wnew =  libpysal.io.open(fname, 'r').read()
    Compare values from old to new.
    >>> wnew.pct_nonzero == w.pct_nonzero
    True
    Clean up temporary file created for this example.
    >>> os.remove(fname)
    """
    self._complain_ifclosed(self.closed)
    if issubclass(type(obj), W):
        try:
            w = full(obj)[0]
        except ValueError:
            w = obj.sparse
        sio.savemat(self.file, {"WEIGHT": w})
        self.pos += 1
    else:
        raise TypeError("Expected a PySAL weights object, got: %s." % (type(obj)))