Clear Filters
Clear Filters

Getting values of nodes from directed graph.

2 views (last 30 days)
Hello Everyone,
I have a directed graph with various nodes, each node has 3 values, Number of station, arrival time and departure time. Now I want to get the value of these nodes and save it in a matrix.
for example, node1 has values(45, 67, 78) and node2 has values(56,23,28) so I want to save the values as this [45 67 78; 56 23 28]
Is there a way to do this? I tried findnode and findobj functions but none of them served the exact purpose. I am stuck on this since a long time and not able to find a solution. any help or guidance will be highly appreciated.
Thanking in advance.

Answers (1)

Shubham Rawat
Shubham Rawat on 2 Feb 2021
Hi Anurag,
You may use structure for the fields. You may use this code for reference:
%here I have created a structure node with 3 fields: numStations, atime, dtime
ns = zeros(1,10); %create an array for number of stations
at = zeros(1,10); %create an array for arrival time
dt = zeros(1,10); %create an array for departure time
node = struct; %create a structure
for i=1:10
% assign a field to the structure
node(i).numStations = ns(i);
node(i).atime = at(i);
node(i).dtime = dt(i);
For more reference about structure you may look in to thee documentation:
Hope this Helps!


Find more on Data Type Identification 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!