How do I generate a 3d plot from an adjacency matrix using force directed algorithm

拜拜、爱过 提交于 2019-12-25 01:55:17

问题


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.


回答1:


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...



来源:https://stackoverflow.com/questions/6663873/how-do-i-generate-a-3d-plot-from-an-adjacency-matrix-using-force-directed-algori

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