Edge Table of Undirected Graph

2 次查看(过去 30 天)
I realize that I am unable to extract the edge and node tables of an undirected graph (ungraph). To explain, take the following adjacency matrices:
>> A = [0 0 0 5 0; 0 0 0 0 6; 0 2 0 0 0; 0 0 3 0 0; 1 0 4 0 0]; % Adjacency matrix of digraph.
>> Asym = 0.5 * (A + A'); % Adjacency matrix of ungraph.
Then, I create the following digraph and ungraph:
>> G = digraph(A); % Digraph associated with A. Note how MATLAB ACKs this request.
G =
digraph with properties:
Edges: [6×2 table]
Nodes: [5×0 table]
>> Gsym = graph(Asym); % Ungraph associated with Asym. Note that MATLAB ACKs differently for an ungraph. This change is quite recent.
<5 nodes, 6 edges, undirected>
Now, I want to look at the edge weights of G and Gsym:
>> G.Edges % This gives the edge table of digraph G.
ans =
6×2 table
EndNodes Weight
________ ______
1 4 5
2 5 6
3 2 2
4 3 3
5 1 1
5 3 4
>> Gsym.Edges % This used to work well. But it now gives an error.
Incorrect number or types of inputs or outputs for function 'getEdgesTable'.
Error in indexing (line 16)
out = getEdgesTable(G);
More importantly, how do I look at the edge table and node table of the ungraph Gsym?

采纳的回答

Walter Roberson
Walter Roberson 2023-11-20
Please show the output of
which -all graph
in R2023b you would expect to see just one line, a variation of
/Applications/MATLAB_R2023b.app/toolbox/matlab/graphfun/@graph/graph.m % graph constructor
I believe that you are getting some other graph() function.
The code in R2020b and before uses a different logic for fetching the edges table.
The code in R2021a and later does use getEdgesTable -- but the internal function is
function E = get.Edges(G)
% This is not called from outside G.Edges (which goes through
% subsref), but is used when calling G.Edges inside graph
% methods and when calling struct on a graph.
E = getEdgesTable(G);
end
Notice that the output is E not out and notice that the containing function is get.Edges not indexing
  3 个评论
Walter Roberson
Walter Roberson 2023-11-20
If you use pathtool you could move that other directory to the end of your MATLAB path.
However if you do that, then in order to deliberately use that other graph() function, you would need to cd to the directory containing the function (source files in the current directory have priority over the rest of the path.)
Kamal Premaratne
Kamal Premaratne 2023-11-21
Thanks Walter for reminding me about pathtool.
After giving it some thought, I decided to remove the package completely. I might have to get it back again, but then I will change the function name from graph() to graphX() or some other name and I will go through the various other function files in the package and do the same change whenever there is a call graph(). That I believe is the cleanest solution.
I am glad you were nice enough to assist me in this matter. Thanks.
Kamal

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by