title: K-means sort labels
body: <p>Assume I have matrix <code>A</code> and I perform K-means clustering on them in MATLAB. I get the following </p>
  
  <pre><code>A=
  
   1    20     5
   1    30    10
   2    60    20
   5   100    45 
  </code></pre>
  
  <p><code>kmeans(A,4)</code> results in the following labels:</p>
  
  <pre><code> 2
   4
   3
   1
  </code></pre>
  
  <p>Now I permute rows of <code>A</code> and I get matrix <code>B</code>:</p>
  
  <pre><code>B =
  
   2    60    20
   1    30    10
   5   100    45
   1    20     5
  </code></pre>
  
  <p>and after applying the <code>kmeans</code> the labels are <code>B1 = [3 1 2 4]</code>, which seems to be random assignment. For example second row of matrix <code>A</code> is in cluster <code>4</code> but second row of matrix <code>B</code> which is the same thing as second row of <code>A</code> is in cluster <code>1</code>.</p>
  
  <p>How can I get the labels in the <code>kmeans</code> such that rows that have highest value always get the same label, for example <code>3</code>, and row that have lowest value always get <code>1</code>?</p>
  
  <p>For example the last row of <code>A</code> gets label <code>3</code>, thus the third row of <code>B</code> also get label <code>3</code>. </p>