title: How should I implement a confusion matrix in Matlab?
body: <p>I know what is a confusion matrix.</p>
  
  <p>Given N classes we have a NxN matrix M where
  - each row is one of the classes
  - each column is one of the classes</p>
  
  <p>M(X,Y) = number of elements which have been classified in class X and should have classified in class Y (of course if X=Y the classification is correct).</p>
  
  <p>Now I have a set of "compound classes" and a <strong>variable</strong> number of classes</p>
  
  <ul>
  <li><p>with "COMPOUND" I mean that one class corresponds to a vector (of <strong>variable</strong> length).
  For example if the class is represented by a 2 element vector,the possible classes will be:</p>
  
  <p>[0,0]</p>
  
  <p>[0,1]   </p>
  
  <p>[1,0]</p>
  
  <p>[1,1]</p></li>
  </ul>
  
  <p>Mi goal is to define a function with:</p>
  
  <ul>
  <li>INPUT: a NxM matrix (where N=number of classified elements,M=number of elements of each class) of classified elements , a NxM matrix of expected class for each element.</li>
  <li>OUTPUT: NXN confusion matrix corresponding to input classes</li>
  </ul>
  
  <p>Example of OUTPUT:</p>
  
  <pre><code>[1 0 0]
  [0 2 0]
  [0 1 0]
  </code></pre>
  
  <p><strong>This matrix is 3x3 matrix.</strong></p>
  
  <p>This means the the total number of classes is 3 and number of classified elements are 4:</p>
  
  <ul>
  <li>one element should have been classified in class 1 and has been classified in class 1</li>
  <li>two elements should have been classified in class 2 and have been classified in class 2</li>
  <li>one element should have been classified in class 3 and has been classified in class 2</li>
  </ul>
  
  <p>(it doesn't matter how the elements are composed of.
  Let's image the classes may be:</p>
  
  <pre><code>[0,0,1]
  [1,0,1]
  [1,1,1]
  </code></pre>
  
  <p>** Example of input matrix (EXPECTEDclasses): **</p>
  
  <pre><code>[0,0,1]
  [1,0,1]
  [1,0,1]
  [1,1,1]
  </code></pre>
  
  <p>** Example of input matrix (OBTAINED classes): **</p>
  
  <pre><code>[0,0,1]
  [1,0,1]
  [1,0,1]
  [1,0,1]   &lt;-- this is the element(line) incorrectly classified
  </code></pre>
  
  <p>How should I do? (the classification is made by a Perceptron or Adaline neuronal network)</p>
  
  <p>Thank you in advance for any hint!</p>