function out = distance_matrix(center, times, data)

    %   This function calculates the distance between each row  in each CENTER  
    %   and each row in DATA with the Short Time Series metric (STS)
    %	distance. Matrix OUT is of size M by N, where M and N are row
    %	dimensions of CENTER and DATA, respectively, and OUT(I, J) is
    %	the distance between CENTER(I,:) and DATA(J,:).

    % ------------------------------------------------------------------- %
    %   Input   :   center = Cluster Centers (prototype V)
    %               times  = time points of experiment
    %               data   = dataset
    % 
    %   Output  :   out    = STS distance matrix 
    % ------------------------------------------------------------------- %

    % ------------------------------------------------------------------- %
    %   Nested STS distance function
    %   Input: x  = Matrix [Ng x ts]
    %          v  = MAtrix [Nc x ts]
    %          t  = time points
    %          Nt =  Size of Time-points

    % Short-Time Series (STS) distance by Moller-Levet et al. (2005)
    function d = STS_dist(x,v,t,Nt)
        d=0;
        for i=1:(Nt-1)
            d=d+((v(i+1)-v(i)-x(i+1)+x(i))/(t(i+1)-t(i)))^2;
        end
    end

    out = zeros(size(center, 1), size(data, 1));

    for k = 1:size(center, 1)
        for j = 1:size(data, 1)
            out(k, j) = STS_dist(data(j, :), center(k, :), times, size(center, 2));
        end
    end
    % ------------------------------------------------------------------- %

end
