title: K means clustering and Matlab
body: <p>I need to use the <code>kmeans</code> function on a rgb image. Each element of the algorithm need to have 3 dimensions, one for each channel of the image. The number of elements will be the total amount of pixels of the image. I need to use <code>kmeans</code> on the cluster #5.</p>
  
  <p>So this is what I tried:</p>
  
  <pre><code>img = imread('mypic.jpg');
  red = img(:,:,1);
  green = img(:,:,2);
  blue = img(:,:,3);
  
  kmeans(red,5)
  </code></pre>
  
  <p><br>
  I dont know if I'm doing it correctly or not. I'm having this error:
  <br><br></p>
  
  <pre><code>??? Error using ==&gt; plus
  Integers can only be combined with integers of the same class, or scalar doubles.
  
  Error in ==&gt; kmeans&gt;distfun at 704
              D(:,i) = D(:,i) + (X(:,j) - C(i,j)).^2;
  
  Error in ==&gt; kmeans at 313
      D = distfun(X, C, distance, 0);
  
  Error in ==&gt; mysegmentation at 9
  kmeans(R,2)
  </code></pre>
  
  <p>Can anyone give me a hand? Thanks</p>