function c_mat = cluster_matrix(varargin)
% function c_mat = cluster_matrix(varargin)
%
% CLUSTER_MATRIX  --  This function takes any number of feature matrices
%                     (one for each class) and computes the cluster
%                     matrix using Euclidean distance
%
% Input Parameters:
%   <M1>  -- Each input parameter is a feature matrix (that is, a matrix
%            with one feature vector per row, and with as many columns as
%            the feature vectors have features) with features from a distinct
%            class.  Note that the function will accept any number of input
%            parameters.
%
% Output Parameter:
%   c_mat -- The cluster matrix, as described in Lab #8
%

means = {};
d = {};
c_mat = [];

for i=1:length(varargin)
    means{i} = mean(varargin{i});
end

for i = 1:length(varargin)
    for j= 1:length(varargin)
        f = varargin{j};
        d{i,j} = sqrt(sum((f - repmat(means{i},[size(f,1),1])).^2,2));
    end
end

for i = 1:length(varargin)
    for j= 1:length(varargin)
        c_mat(i,j) = mean(d{i,j});
    end
end