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: pop_continuousartdet.m
    path of file: ./repos/erplab/pop_functions
    
    the code of the file until where you have to start completion: % pop_continuousartdet.m (alpha version). Reject commonly recorded artifactual potentials (c.r.a.p.)
%
% There are a number of common artifacts that you will see in nearly every EEG data file. These
% include eyeblinks, slow voltage changes (caused mostly by skin potentials), muscle activity
% (from moving the head or tensing up the muscles in the face or neck), horizontal eye movements,
% and various types of C.R.A.P. (Commonly Recorded Artifactual Potentials).
%
% Although we usually perform artifact rejection on the segmented data, it's a good idea to
% examine the raw unsegmented EEG data first. You can usually identify patterns of artifacts,
% make sure there were no errors in the file, etc., more easily with the raw data [1].
%
% crap.m allows you to automatically identify large peak-to-peak differences or extreme amplitude
% values, within a moving window, across your continuous EEG dataset. After performing crap.m,
% artifactual segments will be rejected and replaced by a 'boundary' event code.
%
% USAGE
%
% EEG = pop_continuousartdet(EEG, parameters);
%
% Input:
%
% EEG         - continuous EEG dataset (EEGLAB's EEG structure)
%
% The available parameters are as follows:
%
%         'ampth'     - Thresholds (2 values). E.g. [-100 200]. In case one value is specified it will be taken as
%                       symmetric thresholds. E.g 150 means [-150 150]
%         'winms'     - moving window width in msec (default 2000 ms)
%         'stepms'    - moving window step (default 1000 ms)
%         'chanArray' - channel index(ices) to look f
    
function does not work with multiple datasets';
    error(msgboxText)
end
if ~isempty(EEG.epoch)
    msgboxText =  'pop_continuousartdet() only works on continuous datasets.';
    error(msgboxText)
end
if isempty(EEG.data)
    msgboxText =  'pop_continuousartdet() cannot work on an empty dataset!';
    error(msgboxText);
end

threshType= p.Results.threshType;
ampth     = p.Results.ampth;
winms     = p.Results.winms;
stepms    = p.Results.stepms;
chanArray = p.Results.chanArray;

if strcmpi(p.Results.firstdet, 'on') || strcmpi(p.Results.firstdet, 'yes')
    firstdet = 1;
else
    firstdet = 0;
end

switch(p.Results.History)
    case 'implicit'
        shist = 3; % implicit
    case'script'
        shist = 2; % script
    case 'gui'
        shist = 1; % gui
    otherwise
        shist = 0; % off
end

fcutoff   = p.Results.fcutoff;
forder    = p.Results.forder;
shortisi  = p.Results.shortisi;                                                 % shortest isi in ms
shortseg  = p.Results.shortseg;                                                 % shortest segment in ms
winoffset = p.Results.winoffset;                                                % shortest segment in ms
colorseg  = p.Results.colorseg;

if numel(ampth)~=1 && numel(ampth)~=2
    error('ERPLAB says: for threshold amplitude you must specify 1 or 2 values only.')
end
if ~isempty(forder)
    if mod(forder,2)~=0
        forder = forder+1;
        fprintf('filter order was changed to an even number (%g) because of the forward-reverse filtering.\n', forder)
    end
end
if ischar(fcutoff)
    %
    % Pre-defined bands
    %
    % Removing
    if strcmpi(fcutoff,'rdc') || strcmpi(fcutoff,'rmean')
        fcutoff = [0 0];             % remove mean
    elseif strcmpi(fcutoff,'rdelta') % remove delta
        fcutoff = [4 0.1];
    elseif strcmpi(fcutoff,'rtheta') % remove theta
        fcutoff = [8 4];
    elseif strcmpi(fcutoff,'ralpha') % remove alpha
        fcutoff = [13 8];
    elseif strcmpi(fcutoff,'rbeta')  % remove beta
        fcutoff = [30 13];
    elseif strcmpi(fcutoff,'rgamma') % remove gamma
        fcutoff = [80 30];
        % keeping
    elseif strcmpi(fcutoff,'dc') || strcmpi(fcutoff,'mean') % keep only the mean
        fcutoff = [inf inf];
    elseif strcmpi(fcutoff,'delta') % keep only delta
        fcutoff = [0.1 4];
    elseif strcmpi(fcutoff,'theta') % keep only theta
        fcutoff = [4 8];
    elseif strcmpi(fcutoff,'alpha') % keep only alpha
        fcutoff = [8 13];
    elseif strcmpi(fcutoff,'beta')  % keep only beta
        fcutoff = [13 30];
    elseif strcmpi(fcutoff,'gamma') % keep only gamma
        fcutoff = [30 80];
    elseif strcmpi(fcutoff,'off') || strcmpi(fcutoff,'no') % turn off filtering
        fcutoff = [];
    else
        error('error: unknown pre-defined band. Try with a numeric range of frequencies.')
    end
else
    if ~isempty(fcutoff)
        if numel(fcutoff)~=2
            error('error: 2 values are needed for cutoff.')
        end
        if ~isinf(fcutoff(1)) && ~isinf(fcutoff(2)) && ~isnan(fcutoff(1)) && ~isnan(fcutoff(2))
            if fcutoff(1)~=0 && fcutoff(1)==fcutoff(2)
                error('error: cutoff must have 2 different values. Except for [0 0] or [Inf Inf]. See help pop_continuousartdet')
            end