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_nervus_data.m
    path of file: ./repos/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function out = read_nervus_data(nrvHdr, segment, range, chIdx)
% read_nervus_data  Returns data from Nicolet file.
%
%   OUT = read_nervus_data(NRVHDR, SEGMENT, RANGE, CHIDX) returns data in an n x m array of
%   doubles where n is the number of datapoints and m is the number
%   of channels.
%
%   NRVHDR is a header from the function read_nervus_header
%   SEGMENT is the segment number in the file to read from
%   RANGE is a 1x2 array with the [StartIndex EndIndex]  - default: all
%   and CHIDX is a vector of channel indeces - default: all
%

    
function out = read_nervus_data(nrvHdr, segment, range, chIdx)
% read_nervus_data  Returns data from Nicolet file.
%
%   OUT = read_nervus_data(NRVHDR, SEGMENT, RANGE, CHIDX) returns data in an n x m array of
%   doubles where n is the number of datapoints and m is the number
%   of channels.
%
%   NRVHDR is a header from the function read_nervus_header
%   SEGMENT is the segment number in the file to read from
%   RANGE is a 1x2 array with the [StartIndex EndIndex]  - default: all
%   and CHIDX is a vector of channel indeces - default: all
%
%   FILENAME is the file name of a file in the Natus/Nicolet/Nervus(TM)
%   format (originally designed by Taugagreining HF in Iceland)
%
%   Based on ieeg-portal/Nicolet-Reader
%   at https://github.com/ieeg-portal/Nicolet-Reader
%
% Copyright (C) 2016, Jan Brogger and Joost Wagenaar 
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%  FieldTrip is free software: you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation, either version 3 of the License, or
%  (at your option) any later version.
%
%  FieldTrip is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: $


if nargin == 0
  ft_error('Missing argument');
elseif nargin == 1
  segment = 1;
  range = [1 nrvHdr.targetSampleCount];
  chIdx = nrvHdr.matchingChannels(:);
elseif nargin == 2
  range = [1 nrvHdr.targetSampleCount];
  chIdx = nrvHdr.matchingChannels(:);
elseif nargin == 3
  chIdx = nrvHdr.matchingChannels(:);
end