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: k_nn_classifier.m
    path of file: ./repos/Hyperspectral-Image-Classification/scripts
    
    the code of the file until where you have to start completion: function [z]=k_nn_classifier(Z,v,k,X)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION
%   [z]=k_nn_classifier(Z,v,k,X)
% k-nearest neighbor classifier for c classes (also used in Chapter 4). The
% classification is based on a reference data set, Z, for which the class
% labels of its vectors are known.
%
% INPUT ARGUMENTS:
%   Z:  lxN1  matrix, whose i-th column corresponds to the
%       i-th reference vector.
%   v:  N1-dimensional vector whose i-th  component contains the
%       label of the class where the i-th reference vector belongs.
%   k:  the number of nearest neighbors of the reference set that are
%       taken into account for the classification of a given vector.
%   X:  lxN matrix whose columns are the data vectors to be classfied.

    
function [z]=k_nn_classifier(Z,v,k,X)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION
%   [z]=k_nn_classifier(Z,v,k,X)
% k-nearest neighbor classifier for c classes (also used in Chapter 4). The
% classification is based on a reference data set, Z, for which the class
% labels of its vectors are known.
%
% INPUT ARGUMENTS:
%   Z:  lxN1  matrix, whose i-th column corresponds to the
%       i-th reference vector.
%   v:  N1-dimensional vector whose i-th  component contains the
%       label of the class where the i-th reference vector belongs.
%   k:  the number of nearest neighbors of the reference set that are
%       taken into account for the classification of a given vector.
%   X:  lxN matrix whose columns are the data vectors to be classfied.
%
% OUTPUT ARGUMENTS:
%   z:  N-dimensional vector whose i-th component contains the label
%       of the class where the i-th vector of X is assigned.
%
% (c) 2010 S. Theodoridis, A. Pikrakis, K. Koutroumbas, D. Cavouras
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[l,N1]=size(Z);
[l,N]=size(X);
c=max(v);  %Number of classes
% Computation of the (squared) Euclidean distance of a point from each
% reference vector
for i=1:N
    dist=sum((X(:,i)*ones(1,N1)-Z).^2);
    %Sorting the above distances in ascend