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: read_plexon_ds.m
    path of file: ./repos/malini/Codes/deconvolution - model/spm8/external/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function [dat] = read_plexon_ds(dirname, hdr, begsample, endsample, chanindx)

% READ_PLEXON_DS reads multiple single-channel Plexon files that are
% all contained in a single directory. Each file is treated as a single
% channel of a combined multi-channel d
    
function because that is much slower
    if     filetype_check_extension(fname{i}, '.nex')
      ftype(i) = 1;
    elseif filetype_check_extension(fname{i}, '.plx')
      ftype(i) = 2;
    elseif filetype_check_extension(fname{i}, '.ddt')
      ftype(i) = 3;
    end
  end

  % only remember the filenames that are relevant
  fname = fname(ftype>0);
  ftype = ftype(ftype>0);

  if isempty(fname)
    error('the directory contains no supported files');
  elseif any(ftype~=1)
    error('only nex files are supported in a plexon dataset directory');
  end