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: quantile.m
    path of file: ./repos/CellExplorer/toolboxes/+iosr/+statistics
    
    the code of the file until where you have to start completion: function [q,N] = quantile(X,p,dim,method,weights)
%QUANTILE Quantiles of a sample via various methods.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P) returns quantiles of the values in X.
%   P is a scalar or a vector of cumulative probability values.  When X is
%   a vector, Q is the same size as P, and Q(i) contains the P(i)-th
%   quantile.  When X is a matrix, the i-th row of Q contains the P(i)-th
%   quantiles of each column of X.  For N-D arrays,
%   IOSR.STATISTICS.QUANTILE operates along the first non-singleton
%   dimension.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,DIM) calculates quantiles along
%   dimension DIM.  The DIM'th dimension of Q has length LENGTH(P).
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,DIM,METHOD) calculates quantiles using
%   one of the methods described in http://en.wikipedia.org/wiki/Quantile.
%   The method are designated 'R-1'...'R-9'; the default is R-8 as
%   described in http://bit.ly/1kX4NcT, whereas Matlab uses 'R-5'.
%   
%   Q = IOSR.STATISTICS.QUANTILE(X,P,[],METHOD) uses the specified METHOD,
%   but calculates quantiles along the first non-singleton dimension.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,[],METHOD,WEIGHTS) and
%   IOSR.STATISTICS.QUANTILE(X,P,[],[],WEIGHTS) uses the array WEIGHTS to
%   weight the values in X when calculating quantiles. If no weighting is
%   specified, the method determines the real-valued index in to the data
%   that is used to calculate the P(i)-th quantile. When a weighting array
%   WEIGHTS is specified (WEIGHTS should be the same size as X), this index
%   is mapped to the cumulative weights (the weights are scaled to sum to
%   N(i) - see below), and a new weighted index is returned (using linear
%   interpolation) for the point where the cumulative weights equal the
%   unweighted index. The weighted index is used to calculate the P(i)-th
%   quantile. If the values in WEIGHTS are equal, then the weighted and
%   unweighted index (and correpsonding quantile) are identical. The
%   default method R-8 is used if METHOD is specified as an empty array
%   ([]).
% 
%   [Q,N] = IOSR.STATISTICS.QUANTILE(...) returns an array that is the same
%   size as Q such that N(i) is the number of points used to calculate
%   Q(i).
% 
%   Further reading

    
function [q,N] = quantile(X,p,dim,method,weights)
%QUANTILE Quantiles of a sample via various methods.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P) returns quantiles of the values in X.
%   P is a scalar or a vector of cumulative probability values.  When X is
%   a vector, Q is the same size as P, and Q(i) contains the P(i)-th
%   quantile.  When X is a matrix, the i-th row of Q contains the P(i)-th
%   quantiles of each column of X.  For N-D arrays,
%   IOSR.STATISTICS.QUANTILE operates along the first non-singleton
%   dimension.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,DIM) calculates quantiles along
%   dimension DIM.  The DIM'th dimension of Q has length LENGTH(P).
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,DIM,METHOD) calculates quantiles using
%   one of the methods described in http://en.wikipedia.org/wiki/Quantile.
%   The method are designated 'R-1'...'R-9'; the default is R-8 as
%   described in http://bit.ly/1kX4NcT, whereas Matlab uses 'R-5'.
%   
%   Q = IOSR.STATISTICS.QUANTILE(X,P,[],METHOD) uses the specified METHOD,
%   but calculates quantiles along the first non-singleton dimension.
% 
%   Q = IOSR.STATISTICS.QUANTILE(X,P,[],METHOD,WEIGHTS) and
%   IOSR.STATISTICS.QUANTILE(X,P,[],[],WEIGHTS) uses the array WEIGHTS to
%   weight the values in X when calculating quantiles. If no weighting is
%   specified, the method determines the real-valued index in to the data
%   that is used to calculate the P(i)-th quantile. When a weighting array
%   WEIGHTS is specified (WEIGHTS should be the same size as X), this index
%   is mapped to the cumulative weights (the weights are scaled to sum to
%   N(i) - see below), and a new weighted index is returned (using linear
%   interpolation) for the point where the cumulative weights equal the
%   unweighted index. The weighted index is used to calculate the P(i)-th
%   quantile. If the values in WEIGHTS are equal, then the weighted and
%   unweighted index (and correpsonding quantile) are identical. The
%   default method R-8 is used if METHOD is specified as an empty array
%   ([]).
% 
%   [Q,N] = IOSR.STATISTICS.QUANTILE(...) returns an array that is the same
%   size as Q such that N(i) is the number of points used to calculate
%   Q(i).
% 
%   Further reading
%   
%   Hyndman, R.J.; Fan, Y. (November 1996). "Sample Quantiles in
%     Statistical Packages". The American Statistician 50 (4): 361-365.
%   Frigge, Michael; Hoaglin, David C.; Iglewicz, Boris (February 1989).
%     "Some Implementations of the Boxplot". The American Statistician 43
%     (1): 50-54.
%   
%   See also QUANTILE.

%   Copyright 2016 University of Surrey.

    %% Check input and make default assignments

    assert(isnumeric(X), 'iosr:quantile:invalidX', 'X must be a numeric');
    assert(isvector(p) & isnumeric(p), 'iosr:quantile:invalidP', 'P must be a numeric vector');
    assert(all(p>=0 & p<=1), 'iosr:quantile:invalidP', 'Values in P must be in the interval [0,1].')

    if nargin<2
        error('iosr:quantile:tooFewInputArgs','Not enough input arguments.')
    end