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: coherencyc_unequal_length_trials.m
    path of file: ./repos/EEGapp/EEGapp/custom_stuff/Chronux/chronux_2_12/spectral_analysis/continuous
    
    the code of the file until where you have to start completion: function [Cmn,Phimn,Smn,Smm,f,ConfC,PhiStd,Cerr] = coherencyc_unequal_length_trials( data, movingwin, params, sMarkers )

% This routine computes the average multi-taper coherence for a given set of unequal length segments. It is
% based on modifications to the Chronux routines. The segments are continuously structured in the 
% data matrix, with the segment boundaries given by markers. Below,
% movingwin is used in a non-overlaping way to partition each segment into
% various windows. Th coherence is evaluated for each window, and then the
% window coherence estimates averaged. Further averaging is conducted by
% repeating the process for each segment. 
%
% Inputs: 
%
%   data = data( samples, channels )- here segments must be stacked
%   as explained in the email 
%   movingwin = [window winstep] i.e length of moving
%              window and step size. Note that units here have
%              to be consistent with units of Fs. If Fs=1 (ie normalized)
%              then [window winstep]should be in samples, or else if Fs is
%              unnormalized then they should be in time (secs). 
%   sMarkers = N x 2 array of segment start & stop marks. sMarkers(n, 1) = start
%           sample index; sMarkers(n,2) = stop sample index for the nth segment

    
function [Cmn,Phimn,Smn,Smm,f,ConfC,PhiStd,Cerr] = coherencyc_unequal_length_trials( data, movingwin, params, sMarkers )

% This routine computes the average multi-taper coherence for a given set of unequal length segments. It is
% based on modifications to the Chronux routines. The segments are continuously structured in the 
% data matrix, with the segment boundaries given by markers. Below,
% movingwin is used in a non-overlaping way to partition each segment into
% various windows. Th coherence is evaluated for each window, and then the
% window coherence estimates averaged. Further averaging is conducted by
% repeating the process for each segment. 
%
% Inputs: 
%
%   data = data( samples, channels )- here segments must be stacked
%   as explained in the email 
%   movingwin = [window winstep] i.e length of moving
%              window and step size. Note that units here have
%              to be consistent with units of Fs. If Fs=1 (ie normalized)
%              then [window winstep]should be in samples, or else if Fs is
%              unnormalized then they should be in time (secs). 
%   sMarkers = N x 2 array of segment start & stop marks. sMarkers(n, 1) = start
%           sample index; sMarkers(n,2) = stop sample index for the nth segment
%   params = see Chronux help on mtspecgramc
%
% Output:
%       Cmn     magnitude of coherency - frequencies x iChPairs
%       Phimn   phase of coherency - frequencies x iChPairs
%       Smn     cross spectrum -  frequencies x iChPairs
%       Smm     spectrum m - frequencies x channels
%       f       frequencies x 1
%       ConfC   1 x iChPairs; confidence level for Cmn at 1-p % - only for err(1)>=1
%       PhiStd  frequency x iChPairs; error bars for phimn - only for err(1)>=1
%       Cerr    2 x frequency x iChPairs; Jackknife error bars for Cmn - use only for Jackknife - err(1)=2
%
%       Here iChPairs = indices corresponding to the off-diagonal terms of the
%       lower half matrix. iChPairs = 1 : nChannels*(nChannels-1)/2. So,
%       iChPairs=1,2,3,4,...correspond to C(2,1), C(3,1), C(3,2), C(4,1), etc. 
%       The mapping can be obtained as follows: 
%
%       C(i,j) = Cmn(:,k) where k = j + (1/2)*(i-1)*(i-2)
%
%       The above also applies to phimn, Smn
%
% Note: 
%   segment length >= NW/2 where NW = half bandwidth parameter (see dpss). So the power spectrum will 
%   be computed only for those segments whose length > NW/2. For that reason, the routine returns the 
%   indices for segments for which the spectra is computed. This check is
%   done here since pSpecgramAvg calls it. 

iwAvg = 1; % 0=no weighted average, 1=weighted average
debug = 1; % will display intermediate calcs. 

if nargin < 2; error('avgCoherence:: Need data and window parameters'); end