Getting values of nodes from directed graph.

2 ビュー (過去 30 日間)
Anurag Gupta
Anurag Gupta 2021 年 1 月 30 日
回答済み: Shubham Rawat 2021 年 2 月 2 日
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 Center および File ExchangeWhos についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by