How to graph a connectivity/adjacency matrix in Matlab?

£可爱£侵袭症+ 提交于 2019-12-24 00:28:55

问题


I want to graph the structure of a network (a power grid) in MATLAB. I have a list containing to-from nodes for each branch. I don't have coordinates for the nodes, and the system topology changes for every simulation.

I also need to be able to assign different colors to various lines / nodes, to visualize voltage issues or overloads etc, similar to what I've done using biograph (code below).

The BIOGRAPH function is almost perfect. The drawback is that the lines always go out the "bottom" of the ancestor block, and into the "top" of the descendant. As an ancestor is always displayed above its descendants, the graphs are sometimes very chaotic (for large systems).

I have tried changing the property 'LayoutType' of the biograph from the default 'hierarchical' to both 'radial' and 'equilibrium', but this gives even worse results.

Is what I'm asking possible? It doesn't need to be a perfect solution, any improvements would be great.

This is the code I use now:

%% Plot biograph
Sys = sparse(from,to,1,s,s);  

SysTri = tril(Sys + Sys'); 
bg = biograph(SysTri,[],'ShowArrows','off','ShowWeights','off');
h = view(bg);  

 %% Color faulted line:
set(h.nodes(newFaultNodes),'Color',[1 0.4 0.4]);
fowEdges = getedgesbynodeid(h,get(h.Nodes(newFaultNodes),'ID'));
revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(newFaultNodes)),'ID'));
edges = [fowEdges;revEdges];
set(edges,'LineColor',[1 0 0])
set(edges,'LineWidth',2)

回答1:


Try out matlab-bgl. It links to the Boost Graph library and includes a few useful layout algorithms. You can then use gplot to visualize.

gplot(A, fruchterman_reingold_force_directed_layout(A));


来源:https://stackoverflow.com/questions/16315322/how-to-graph-a-connectivity-adjacency-matrix-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!