Efficient way to connect based on n x 2 array

1 view (last 30 days)
Hi, I have a vector of size n x 2 which is build up like
[a,b ; d,e ; b,f ; e,g ; ...]
what means that a is connected to b, d is connected to e, b is connected to f and so on. As a is connected to b and b is also connected to f, I want to find chains like (a,b,f,...).
As the length of the vector n is much larger than 1 million, I would like to do this in an efficient way, because just using find with loops works, but is taking a very long time. So if someone has an idea to speed it up I would be pretty happy.
BR Olli

Answers (1)

Cam Salzberger
Cam Salzberger on 14 Mar 2019
Hello Olli,
Consider looking into various graph search algorithms, as that is exactly the field that explores "doing this efficiently". There are several functions for this built into MATLAB, and you would simply need to define the graph in the expected way.
-Cam

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!