You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tess_cluster_functional.m
    path of file: ./repos/brainstorm3/toolbox/connectivity
    
    the code of the file until where you have to start completion: function [Labels,err] = tess_cluster_functional(sSurf, ImagingKernel, Leadfield, Atlas)
% TESS_CLUSTER_FUNCTIONAL: 
%
% USAGE:  Labels = tess_cluster_functional(Surface, Results.ImagingKernel, HeadModel.Gain(Results.GoodChannel,:))
%
% INPUTS: 
%    - sSurf           : tesselation structure (Faces,Vertices,VertConn)
%    - ImagingKernel   : N-source x N-channel sensor to source projection matrix
%    - Leadfield       : N-source gain matrix from the head model
%
% OUTPUTS:
%    - Labels : N-source vector with each number corresponding to an
%    agregation of source (0 means not assigned).
%
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
% 
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.

    
function [Labels,err] = tess_cluster_functional(sSurf, ImagingKernel, Leadfield, Atlas)
% TESS_CLUSTER_FUNCTIONAL: 
%
% USAGE:  Labels = tess_cluster_functional(Surface, Results.ImagingKernel, HeadModel.Gain(Results.GoodChannel,:))
%
% INPUTS: 
%    - sSurf           : tesselation structure (Faces,Vertices,VertConn)
%    - ImagingKernel   : N-source x N-channel sensor to source projection matrix
%    - Leadfield       : N-source gain matrix from the head model
%
% OUTPUTS:
%    - Labels : N-source vector with each number corresponding to an
%    agregation of source (0 means not assigned).
%
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
% 
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Sebastien Dery, 2013
%
% Init varout
Labels = [];
err = [];

% Making sure we have all we need
if isempty(sSurf)
    err = 'Surface structure is empty';
    return;
end