title: How to find connected components in Matlab?
body: <p>array A =</p>
  
  <pre><code> 2     3
   2     5
   4     8
   5     6
   7     8
  </code></pre>
  
  <p>I'd like to get the result as 'conidx = [2 3 5 6] and [4 7 8]'.</p>
  
  <hr>
  
  <p>One of the values of [2 3] exists in the 2nd row,</p>
  
  <p>One of the values of [2 5] exists in the 4th row,</p>
  
  <p>so [2 3], [2 5] and [5 6] are connected, </p>
  
  <p>finally I can get the connected indices as [2 3 5 6].</p>
  
  <p>Otherwise, one of the values of [4 8] exists in the 5th row, </p>
  
  <p>so [4 8] and [7 8] are connected, finally I can get the connected indices as [4 7 8].</p>
  
  <p>[3]&lt;-->[2]&lt;-->[5]&lt;-->[6] and [4]&lt;-->[8]&lt;-->[7]</p>