def METHOD_NAME(vertices, faces, labels, fileName, n = 280, map = 'gist_ncar'):
    '''
    This function can be used for writing a labeled mesh to a ply file.
    Parameters:
        @vertices: numpy.ndarray
                   vertices of the input mesh
        @faces: numpy.ndarray
                faces of the input mesh
        @labels: numpy.ndarray
                 labels for each vertex
        @fileName: string
                   output file path and name
        @n: int
            total number of the functional regions
    '''
    # create the necessary PlyElement instances
    v = [tuple(vertices[t]) for t in range(len(vertices))]
    f = [tuple() for t in range(len(faces))]
    import matplotlib as mpl
    norm  = mpl.colors.Normalize(vmin = 1, vmax = n)
    import matplotlib.pyplot as plt
    cmap = plt.cm.get_cmap(map)
    for idx in range(len(faces)):
        face = faces[idx]
        c = list(labels[face])
        if c.count(c[0]) > 1:
            rgba = cmap(norm(c[0]))
        else:
            rgba = cmap(norm(c[1]))
        f[idx] = tuple([face, int(rgba[0]*255), int(rgba[1]*255), int(rgba[2]*255)])
    v = np.asarray(v, dtype = [('x', 'float64'), ('y', 'float64'), ('z', 'float64')])
    f = np.asarray(f, dtype = [('vertex_indices', 'i4', (3,)), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])
    el1 = PlyElement.describe(v, 'vertex')
    el2 = PlyElement.describe(f, 'face')
    # instantiate PlyData and serialize
    PlyData([el1, el2]).write(fileName)