
function [ groupStats, orderedGroups ] = processKMeansResults( ID, idx, ...
    groupingCriteria, masterFileOutputID, titleName, DEBUG )
    
    if( length( idx ) ~= length( groupingCriteria ) )
        disp('EEEK!');
        pause;
    end

    groupIDs = '';
    groupStr = '';
    for( i = 1 : length( idx ))
%         fprintf( fileOutputID, '%s \t %d \n', groupingCriteria(i), idx(i) );
        gID = [ groupingCriteria(i) num2str( idx(i) )];
        groupIDs = [ groupIDs ; gID ];
        groupStr = [ groupStr gID ];
    end

    % ------------- work out the confusion matrix -------------------------

    groups = unique( groupIDs, 'rows' );
    noOfGroups = length( groups );
    orderedGroups = sort(cellstr(groups));
    groupStats = [];
    for( i = 1 : noOfGroups )
        groupStats(i) = ((length( strfind( groupStr, char(orderedGroups(i)))))/length( idx ) ) * 100;
    end
    
    if(DEBUG == 1)
        figure(1);
        bar( groupStats );
        set( gca, 'XTickLabel', orderedGroups );
        title([ titleName ' ' ID]);
    end
end