Azzera filtri
Azzera filtri

How do I use adj2gephilab function for csv expot to gephi for network diagram representation

6 visualizzazioni (ultimi 30 giorni)
Can someone help me to assist how to use the function EdgeL=adj2gephilab(filename,ADJ,parameters)
I want to export my trade date between countries and show that in a Networt in gephi. What do I have to change in this code.
My Network structure from Matlab is stored in the variable G whcih consits of two matrices, labled "G.Edges" and "G.Nodes"
the Tratding data between the countries are stored inteh matrix "p_flow_res.F5(21).M"
the file is labeled "indicators.m"
I dont know how to use this plug in. It is all stord in the same folder.
I thougt I just chagne teh first function line with my variables like this:
function EdgeL=adj2gephilab(indicators,G,p_flow_res.F5(21).M)
But I get the error liek this:
>> adj2gephilab
File: adj2gephilab.m Line: 1 Column: 52
Invalid use of operator.
How to use this plugIn, which I got from Fabio Vanni
code fo file adj2gephilab.m :
function EdgeL=adj2gephilab(filename,ADJ,parameters)
% Convert ana adjacency matrix of a graph to 2 spreadhseets csv files
% one for the edge table and the other for node table.
% The files _node.csv and _edge.csv have to be open
%in Gephi via Data Laboratory.
% filename: string for the prefix name of the two files .csv
% ADJ: the adjacency matrix
% parameters: vector as properties of the node to use as
% attributes of them.
% two csv spreadsheet files:
% filename_node.csv
% filename_edge.csv
% EdgeL = it returns the edge list corresponing to the
% adjacency matrix. (it can be saved to be open in Gephi too)
% The two files must be open in Gephi via the Data Laboratory
n=size(ADJ,1); % square adjacency matrix
if nargin<3
parameters=ones(n,1);% all nodes have the same attributes
%% Node Table:
% header for node csv
fidN = fopen(nodecsv,'w','native','UTF-8'); % best format for gephi
for i=2:n+1,
fprintf(fidN,'%s\n',[ num2str(i-1) ';"Node ' num2str(i-1) '"'...
';' num2str(ps(i-1))]);
%% Edge Table
S=EdgeL(:,1); % sources
T=EdgeL(:,2); % targets
W = EdgeL(:,3); % weights
fidE = fopen(edgecsv,'w','native','UTF-8');
% header for edge csv
for i=2:length(S)+1,
fprintf(fidN,'%s\n',[ num2str(S(i-1)) ';' num2str(T(i-1)) ';'...
'"Edge from ' num2str(S(i-1)) ' to ' num2str(T(i-1)) '"' ';'...
%% Aux function
function EdgeL=conv_EdgeList(adj)
% convert adj matrix to edge list
n=size(adj,1); % number of nodes
edges=find(adj>0); % indices of all edges
for e=1:n_e
[i,j]=ind2sub([n,n],edges(e)); % node indices of edge e
EdgeL(e,:)=[i j adj(i,j)];

Risposte (1)

Jaynik il 10 Apr 2024
Hi Peter,
The error you are getting is likely because you are trying to pass "p_flow_res.F5(21).M" as a single parameter, but MATLAB is interpreting the '.' as an operator. Instead of changing the function directly, you should pass this as a separate variable and call the function in your code.
Here is how you might modify the function call in your script:
filename = 'indicators';
ADJ = G;
parameters = p_flow_res.F5(21).M;
EdgeL = adj2gephilab(filename, ADJ, parameters); % Call to the function
Note that, "adj2gephilab" should be on the MATLAB path.
  2 Commenti
PETER il 10 Apr 2024
Hi, Thanks,
unfortunatelly the code is still not working:
filename = 'indicators';
ADJ = G;
parameters = p_flow_res.F5(21).M;
EdgeL = adj2gephilab(filename, ADJ, parameters);
it gives these Errors:
Operator '>' is not supported for operands of type 'graph'.
Error in adj2gephilab>conv_EdgeList (line 61)
edges=find(adj>0); % indices of all edges
Error in adj2gephilab (line 40)
Error in gephi_2st (line 4)
EdgeL = adj2gephilab(filename, ADJ, parameters);
would it be acceptable for you to make a online zoom?
Jaynik il 10 Apr 2024
Modificato: Jaynik il 10 Apr 2024
As per the documentation, the function "adj2gephilab" expects an adjacency matrix as input but from the error it seems that it is receiving a graph object. You can use the "adjacency" function to obtain the adjacency matrix for graph "G".
ADJ = adjacency(G);
If "G" is weighted graph, use this:
ADJ = adjacency(G, 'weighted');
Refer the following for more info on "adjacency":

Accedi per commentare.


Scopri di più su Graph and Network Algorithms in Help Center e File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by