Getting values of nodes from directed graph.

1 次查看(过去 30 天)
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.

回答(1 个)

Shubham Rawat
Shubham Rawat 2021-2-2
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!

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by