function C = confusion(y1, y2, classes)
% returns the confusion matrix for two vectors, given possible classes
% enumerated in vector classes.
% C is number of classes x number of classes
% e.g. to find confusion matrix for a set of binary targets, compared to some 
% outputs y, on a two-class problem we could use 
% C = confusion(targets, y>=0.5, [1 0]);
% an example where y1 & y2 are equal will lead to a diagonal matrix - no confusion.

for i = 1:length(classes)
   for j = 1:length(classes)
     C(i,j) = sum((y1 == classes(i)) & (y2 == classes(j)))
   end
end