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?

 Réponse acceptée

Walter Roberson
Walter Roberson le 20 Nov 2023

0 votes

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 commentaires

Kamal Premaratne
Kamal Premaratne le 20 Nov 2023
Thank you so much Walter.
After your response, I went through the *.m files in my computer, and your are right, I have another graph() function which turns out to be part of a package that I downloaded for the purpose of computing the global and local clustering coefficients. It is quite likely that MATLAB is reading this instead of its own function. I may have to rename the graph() that I downloaded. Or, is there any way that I could instruct MATLAB not to use a function that resides in a specified directory?
Thanks again.
Kamal
Walter Roberson
Walter Roberson le 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 le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by