title: Matlab/Octave 1-of-K representation
body: <p>I have a y of size 5000,1 (matrix), which contains integers between 1 and 10. I want to expand those indices into a 1-of-10 vector. I.e., y contains 1,2,3... and I want it to "expand" to:</p>
  
  <pre><code>1 0 0 0 0 0 0 0 0 0 
  0 1 0 0 0 0 0 0 0 0
  0 0 1 0 0 0 0 0 0 0 
  </code></pre>
  
  <p>What is the best way to do that?</p>
  
  <p>I tried: </p>
  
  <pre><code>Y = zeros(5000,10); Y(y) = 1; 
  </code></pre>
  
  <p>but it didn't work. </p>
  
  <p>It works for vectors though:</p>
  
  <p>if <code>y = [2 5 7]</code>, and <code>Y = zeros(1,10)</code>, then <code>Y(y) = [0 1 0 0 1 0 1 0 0 0]</code>.</p>