Why i can't use the function Graph::isEdge in my code??

2 ビュー (過去 30 日間)
John Blue
John Blue 2019 年 2 月 16 日
回答済み: Steven Lord 2019 年 2 月 16 日
This is my code and i try to create a graph
clear all;
fileID = fopen("routers_modify_airports.dat");
data = textscan(fileID,'%q %q');
fclose(fileID);
Data_of_ports = [data{:}];
unique_elements = unique(Data_of_ports);
G = graph;
for i = 1 : length(unique_elements)
G = addnode(G,unique_elements(i));
end
for i = 1: length(Data_of_ports)
G = addedge(G,Data_of_ports(i,1),Data_of_ports(i,2));
end
And i have a problem in function addedge because i have two time the same edge . For exapmle
'AER' 'KZN'
'ASF' 'KZN'
'ASF' 'MRV'
'CEK' 'KZN'
'CEK' 'OVB'
'DME' 'KZN'
'DME' 'NBC'
'DME' 'TGK'
'DME' 'UUA'
'EGO' 'KGD'
'EGO' 'KZN'
'GYD' 'NBC'
'KGD' 'EGO'
'KZN' 'AER'
I find a function who check if is the edge exists. But i can't use it.
for i = 1: length(Data_of_ports)
if (Graph::isEdge(G, [[Data_of_ports(i,2), Data_of_ports(i,1)]] )) == false
G = addedge(G,Data_of_ports(i,1),Data_of_ports(i,2));
end
end
And i have this Error
Screenshot_1.png
Do you know how to use this function???
  1 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 16 日
編集済み: madhan ravi 2019 年 2 月 16 日
That function can be used only in MUPAD notebooks where as you are using it in MATLAB script.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2019 年 2 月 16 日
As madhan ravi said, the function you found is only for MuPAD. Since you're working with the graph object included in MATLAB, use the findedge function instead.
Since both findedge and addedge accept vectors of source and target data, you don't even need the for loop. In fact, you may not even need findedge if you're using a release that supports multigraph (release R2018a) as you could add the edge regardless of whether or not it exists and simplify the multigraph to turn it into a simple (at most one edge between any pair of nodes) at the end.

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by