% calculate the euclidean distance
% input must be row vector

function [Dist] = euc_distance(X, Y, flag, Weight)

[junk, cx] = size(X);
Dist = 0;
Dis(1, cx) = 0;

for i = 1 : cx
    
    if flag(1, i) == 0 % if the attribute is categorical
        
        if X(1, i) == Y(1, i) % if the attributes i of X and Y are equal
            
            Dis(1, i) = 0;
            
        else 
            
            Dis(1, i) = 1;
            
        end
        
    else % if the attribute is numerical
            
           Dis(1, i) = (X(1,i) - Y(1,i)).^2;
    end
    
end

cap = size(Weight); %used to catch case in which no weight attached
if cap ~= 0
Dist = sum(Weight.* Dis);
end

