MATLAB: Graph how to get every connected nodes from this specific graph

arraygraphMATLAB

Hi, I have graph that is described in this way
U = {[1 3],[1 4],[1 5],[5 2]};
and it looks like this
How can i get two arrays, s array would show first node and t array would show accordingly the next node connected to it.
Example below.
s[1 1 1 2 3 4 5 5]
t[3 4 5 5 1 1 1 2]
Thanks in advance.

Best Answer

Hi,
you find s and t by using:
U = {[1 3],[1 4],[1 5],[5 2]};
A = cat(1,U{:});
s = A(:,1);
t = A(:,2);
Best regards
Stephan