Edge Table of Undirected Graph

3 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 20 Nov 2023
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 Comments
Walter Roberson
Walter Roberson on 20 Nov 2023
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 on 21 Nov 2023
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

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!