title: How can I select rows with specific column values from a matrix?
body: <p>I have a matrix train3.</p>
  
  <pre><code>1    2    3    4    5    6    7
  2   12   13   14   15   16   17
  3   62   53   44   35   26   17
  4   52   13   24   15   26   37
  </code></pre>
  
  <p>I want to select only those rows of whose 1st columns contain specific values (in my case 1 and 2).</p>
  
  <p>I have tried the following,</p>
  
  <pre><code>&gt;&gt; train3
  train3 =
      1    2    3    4    5    6    7
      2   12   13   14   15   16   17
      3   62   53   44   35   26   17
      4   52   13   24   15   26   37
  
  &gt;&gt; ind1 = train3(:,1) == 1
  ind1 =
     1
     0
     0
     0
  
  &gt;&gt; ind2 = train3(:,1) == 2
  ind2 =
     0
     1
     0
     0
  
  &gt;&gt; mat1 = train3(ind1, :)
  mat1 =
     1   2   3   4   5   6   7
  
  &gt;&gt; mat2 = train3(ind2, :)
  mat2 =
      2   12   13   14   15   16   17
  
  &gt;&gt; mat3 = [mat1 ; mat2]
  mat3 =                                                                                                                                         
      1    2    3    4    5    6    7
      2   12   13   14   15   16   17
  
  &gt;&gt;
  </code></pre>
  
  <p><strong>Is there any better way to do this?</strong></p>