function [K] = confusion_matrix(varargin)

%function K = confusion_matrix(M, fm_test1, fm_test2, ... )
%
% CONFUSION_MATRIX -- Calculates a confusion matrix for a classifier M, with
%                     instances from each class in fm_test1, fm_test2, etc.
%
% Input Parameters:
%   M         --  Matrix of "best representative" feature vectors, with
%                 one representative per column. 
%   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:
%   K  --  the confusion matrix indicating performance of the given classifier
%          on the given data sets.  The rows of K correspond to the classes in the
%          rows of M; the columns of K correspond to the classes of the input
%          feature matrices.
%

if length(varargin) < 1 + size(varargin{1},1)
    error('Not enough input arguments.  One needed for each class of the classifier.');
end

M = varargin{1};

for j = 1:length(varargin)-1
    labels = feature_classifier(M,varargin{j+1});
    for i = 1:length(varargin)-1
        K(i,j) = length(find(labels==i))/length(labels);
    end
end
