forked from ivanbrugere/matlab-networks-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadj2str.m
executable file
·28 lines (24 loc) · 958 Bytes
/
adj2str.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
%##################################################################
% Convert an adjacency matrix to a one-line string representation of a graph.
%
% INPUTS: adjacency matrix, nxn
% OUTPUTS: string
%
% Note 1: The nomenclature used to construct the string is arbitrary.
% Here we use .i1.j1.k1,.i2.j2.k2,....
% In '.i1.j1.k1,.i2.j2.k2,....',
% "dot" signifies new neighbor, "comma" next node
% Note 2: Edge weights are not reflected in the string representation.
% Example: [0 1 1; 0 0 0; 0 0 0] <=> .2.3,,,
%
% Other routines used: kneighbors.m
% GB: last updated, Sep 25 2012
%##################################################################
function str=adj2str(adj)
str='';
n=length(adj);
for i=1:n
neigh=kneighbors(adj,i,1);
for k=1:length(neigh); str=strcat(str,'.',num2str(neigh(k))); end
str=strcat(str,','); % close this node's neighbors list
end