There is a network in the dormitory, and the matrix needs to be converted into a network map to make it look a little bit. So I wrote such a function here.
The function is to change the adjacent matrix or associated matrix into a network diagram, but I can only convert it to an undirected graph here. I still need to study the arrow of the directed graph.The annotation function can be called.
% Function name netplot % use method input help netplot % No Return Value
% Function can only process undirected graph % Author: tiandsp % last modification: 2012.12 . 26 Function Netplot (A, flag) % call Method Input netplot (A, flag), no return value % A is an adjacent matrix or association matrix % flag = 1 % Flag = 2 When processing the association matrix % function, only undirected graphs can be processed. If Flag =1 % Adjacent matrix indicates undirected graph nd_netplot (a); return; End If Flag = 2 % Join matrix: undirected graph [m n] = Size (a); % W = Zeros (M, M ); For I = 1 : N = Find (A (:, I )~ = 0 ); W (( 1 ), ( 2 ) = 1 ; W (( 2 ), ( 1 ) = 1 ; End Nd_netplot (w); return; End Function Nd_netplot (a) [N] = Size (a); W = Floor (SQRT (n); H = Floor (N/ W); x = []; Y = []; For I = 1 : H % gives the range of random points to be generated, so that the display distribution is wider. For J = 1 : W x = [X 10 * Rand ( 1 ) + (J- 1 )* 10 ]; Y = [Y 10 * Rand ( 1 ) + (I- 1 )* 10 ]; End End Ed = N-H * W; For I = 1 : Ed x = [X 10 * Rand (1 ) + (I- 1 )* 10 ]; Y = [Y 10 * Rand ( 1 ) + H * 10 ]; End Plot (x, y, ' R * ' ); Title ( ' Network Topology ' ); For I = 1 : N For J = I: N If A (I, j )~ = 0 C = Num2str (a (I, j); % convert the weight in a to plain text (X (I) + X (j ))/ 2 , (Y (I) + Y (j ))/2 , C, ' Fontsize ' , 10 ); % Display Edge Weight line ([X (I) x (j)], [Y (I) y (j)]); % line End Text (X (I), y (I), num2str (I ), ' Fontsize ' , 14 , ' Color ' , ' R ' ); % Display vertex serial number hold on; End End End End
I will not say much about the call methods.
Below is a graph with 10 nodes (I still like to upload images for image creation ):