title: MATLAB - generate confusion matrix from classifier
body: <p>I have some test data and labels:</p>
  
  <pre><code>testZ = [0.25, 0.29, 0.62, 0.27, 0.82, 1.18, 0.93, 0.54, 0.78, 0.31, 1.11, 1.08, 1.02];
  
  testY = [1 1 1 1 1 2 2 2 2 2 2 2 2];
  </code></pre>
  
  <p>I then sort them:</p>
  
  <pre><code>[sZ, ind] = sort(testZ); %%Sorts Z, and gets indexes of Z
  sY = testY(ind); %%Sorts Y by index
  [N, n] = size(testZ');
  </code></pre>
  
  <p>This will then give the sorted Y data. At each element of the sorted Y data, I want to classify each point to the left as being of type 1 and everything to the right being class 2; This will then be repeated for every point of the data. How can I do this and find out for each element the variables:</p>
  
  <ul>
  <li>TP(true positive) - the elements correctly marked as 1</li>
  <li>FP(false positive) - the elements incorrectly marked as 1</li>
  <li>TN(true negative) - the elements correctly marked as 2</li>
  <li>FN(false negatives) - the elements incorrectly marked as 2</li>
  </ul>
  
  <p>The purpose of this is so that I can create an ROC curve for the classifier as part of some school work.</p>