如何使用力导向算法从邻接矩阵生成3d图 [英] How do I generate a 3d plot from an adjacency matrix using force directed algorithm

查看:83
本文介绍了如何使用力导向算法从邻接矩阵生成3d图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个接受邻接矩阵作为用户输入的代码,并创建了该矩阵的3d散点图.我想在未连接的节点之间分配排斥力,并在连接的节点之间分配吸引力,以使节点根据作用在其上的净力进行位移.这必须在3d中.

I have created a code that accepts an adjacency matrix as input from a user and create a 3d scatter plot of the matrix. I want to assign a repulsive force between unconnected nodes and an attractive force between connected nodes such that the nodes are displaced according to the net force acting on them. This has to be in 3d.

推荐答案

下面是一个示例,显示在给定邻接矩阵和顶点坐标的情况下,我们如何绘制图形的3D散点图:

Here is an example showing how, given an adjacency matrix and the coordinates of the vertices, we plot a 3D scatter of the graph:

%# sample adjacency matrix and 3D coordinates of points
N = 30;                                      %# number of vertices
[adj,XYZ] = bucky;
adj = full(adj); adj = adj(1:N,1:N);
x = XYZ(1:N,1); y = XYZ(1:N,2); z = XYZ(1:N,3);
labels = cellstr( num2str((1:N)','%02d') );  %'# nodes labels

%# another sample data
%#x = rand(N,1);          %# x-coords of vertices
%#y = rand(N,1);          %# y-coords
%#z = rand(N,1);          %# z-coords
%#adj = rand(N,N)>0.7;    %# adjacency matrix

%# plot graph in 3D
[r c] = find(adj);
p = [r c]';              %'# indices
plot3(x(p), y(p), z(p), 'LineWidth',2, 'Color',[.4 .4 1], ...
    'Marker','o', 'MarkerSize',10, ...
    'MarkerFaceColor','g', 'MarkerEdgeColor','g')
text(x, y, z, labels, ...
    'EdgeColor','g', 'BackgroundColor',[.7 1 .7], ...
    'VerticalAlignment','bottom', 'HorizontalAlignment','left')
axis vis3d, box on, view(3)
xlabel('x'), ylabel('y'), zlabel('z')

恐怕另一部分会涉及更多,您必须证明自己已经付出了一定的努力,才能有人帮助您...

I'm afraid the other part is much more involved, and you would have to show that you put some effort into it before someone will attempt to help you...

这篇关于如何使用力导向算法从邻接矩阵生成3d图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆