Edge Table of Undirected Graph
3 次查看(过去 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?
0 个评论
采纳的回答
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
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.)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!