# confMatrix

## PURPOSE

Generates a confusion matrix according to true and predicted data labels.

## SYNOPSIS

function CM = confMatrix( IDXtrue, IDXpred, ntypes )

## DESCRIPTION

     Generates a confusion matrix according to true and predicted data labels.

     CM(i,j) denotes the number of elements of class i that were given label
     j.  In other words, each row i contains the predictions for elements whos
     actual class was i.  If IDXpred is perfect, then CM is a diagonal matrix
     with CM(i,i) equal to the number of instances of class i.

     To normalize CM to [0,1], divide each row by sum of that row:
      CMnorm = CM ./ repmat( sum(CM,2), [1 size(CM,2)] );

     USAGE
      CM = confMatrix( IDXtrue, IDXpred, ntypes )

     INPUTS
      IDXtrue     - [nx1] array of true labels [int values in 1-ntypes]
      IDXpred     - [nx1] array of predicted labels [int values in 1-ntypes]
      ntypes      - maximum number of types (should be > max(IDX))

     OUTPUTS
      CM          - ntypes x ntypes confusion array with integer values

     EXAMPLE
      IDXtrue = [ones(1,25) ones(1,25)*2];
      IDXpred = [ones(1,10) randint2(1,30,[1 2]) ones(1,10)*2];
      CM = confMatrix( IDXtrue, IDXpred, 2 )
      confMatrixShow( CM, {'class-A','class-B'}, {'FontSize',20} )

     See also CONFMATRIXSHOW

     Piotr's Image&Video Toolbox      Version 2.12
     Copyright 2008 Piotr Dollar.  [pdollar-at-caltech.edu]
     Please email me if you find bugs, or have suggestions or questions!
     Licensed under the Lesser GPL [see external/lgpl.txt]

## CROSS-REFERENCE INFORMATION

This function calls:

- checkNumArgs Helper utility for checking numeric vector arguments.

This function is called by: