Getting values of nodes from directed graph.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Shubham Rawat
am 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);
end
For more reference about structure you may look in to thee documentation:
Hope this Helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!