function C = cluster_matrix(varargin)

%function C = cluster_matrix_tt(M, fm_test1, fm_test2, ... )
%
% CLUSTER_MATRIX_TT -- Calculates a confusion matrix for a classifier M, with
%                      instances from each class in fm_test1, fm_test2, etc.
%
% Input Parameters:
%   M         --  Classifier matrix computed using train_classifier
%   fm_train? --  Each mf_train? is a feature matrix containing 
%                  instances from a single class.  fm_train1 contains 
%                  instances from the first class, fm_train2 contains
%                  instances from the second class, and so on.  There
%                  should be one fm_train? per class in M 
%
% Output Parameters:
%   C  --  the cluster matrix indicating performance of the given classifier
%          on the given data sets
%

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

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

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

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