It was of great help. Thanks! Being occasional user of Matlab, however, the ideal output for me would have been a matrix, or at least some properly delimited list. I had a hard time converting the output into proper adjacency matrix I needed. This was due to different number of spaces before, within, and after each element. It would be great if the output is in the form 1,2,3 with no spaces anywhere. I used Matlab7.10 (R2010a).