Find graph node names beginning with a few characters
1 view (last 30 days)
Show older comments
Kamal Premaratne
on 7 Oct 2021
Commented: Kamal Premaratne
on 8 Oct 2021
Is there a way to find out all the node names of a graph that begins with a few characters?
For example, I am working with the CElegans digraph (wormwiring.org). It has nodes named 'DA01', 'DA02', etc. I want to know all the node names that begin with the characters 'DA'.
Thank you so much.
Kamal
0 Comments
Accepted Answer
Steven Lord
on 7 Oct 2021
Using a modified version of one of the documentation examples and splitting the code into multiple lines for ease of explanation.
A = triu(magic(4));
names = {'alpha' 'beta' 'gamma' 'alphabet'};
G = graph(A,names,'upper','omitselfloops')
listOfNames = G.Nodes.Name
whichNodesStartWithA = startsWith(listOfNames, 'a')
namesStartingWithA = listOfNames(whichNodesStartWithA)
whichNodesAreTheyInG = findnode(G, namesStartingWithA)
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!