function [K] = GaussianKernel(arg,X,Xt)

if nargin < 2
error('no input data');
end

if nargin < 3
    %generate square matrix for training
    [m,k] = size(X); 
    %Ktemp = zeros(m);REMARK: for radial basis function it is neednot to
    %do mormalization, for k(i,i) = 1.
    K = zeros(m);
    for i = 1:m
                U = repmat(X(i,:),[m,1]) - X;
                K(i,:) = exp(-sum(U.*U,2)/arg);       
    end
end
    
if nargin == 3
    [m k] = size(X);
    [n k2] = size(Xt);
    K = zeros(m,n);
         if m<=n            
            for i = 1:m
                U = repmat(X(i,:),[n,1]) - Xt;
                K(i,:) = exp(-sum(U.*U,2)/arg);        
            end
        else % m>n
            for i = 1:n
                U = repmat(Xt(i,:),[m,1]) - X;
                K(:,i) = exp(-sum(U.*U,2)/arg);
            end
         end
end