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

1 visualización (últimos 30 días)
Hi,
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 https://de.mathworks.com/matlabcentral/fileexchange/51146-adj2gephilab Fabio Vanni
Thanks
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.
% INPUTS:
% 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.
% OUTPUTS:
% 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
nodecsv=[filename,'_node.csv'];
edgecsv=[filename,'_edge.csv'];
n=size(ADJ,1); % square adjacency matrix
if nargin<3
parameters=ones(n,1);% all nodes have the same attributes
end
ps=parameters;
%% Node Table:
% header for node csv
fidN = fopen(nodecsv,'w','native','UTF-8'); % best format for gephi
fprintf(fidN,'%s\n','Id;Label;Attribute');
%
for i=2:n+1,
fprintf(fidN,'%s\n',[ num2str(i-1) ';"Node ' num2str(i-1) '"'...
';' num2str(ps(i-1))]);
end
fclose(fidN);
%% Edge Table
EdgeL=conv_EdgeList(ADJ);
S=EdgeL(:,1); % sources
T=EdgeL(:,2); % targets
W = EdgeL(:,3); % weights
fidE = fopen(edgecsv,'w','native','UTF-8');
% header for edge csv
fprintf(fidE,'%s\n','Source;Target;Label;Weight');
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)) '"' ';'...
num2str(W(i-1))]);
end
fclose(fidE);
%% 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
n_e=length(edges);
EdgeL=zeros(n_e,3);
for e=1:n_e
[i,j]=ind2sub([n,n],edges(e)); % node indices of edge e
EdgeL(e,:)=[i j adj(i,j)];
end

Respuestas (1)

Jaynik
Jaynik el 10 de Abr. de 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 comentarios
PETER
PETER el 10 de Abr. de 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)
EdgeL=conv_EdgeList(ADJ);
Error in gephi_2st (line 4)
EdgeL = adj2gephilab(filename, ADJ, parameters);
__________
would it be acceptable for you to make a online zoom?
Jaynik
Jaynik el 10 de Abr. de 2024
Editada: Jaynik el 10 de Abr. de 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": https://www.mathworks.com/help/matlab/ref/graph.adjacency.html

Iniciar sesión para comentar.

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by