开发者

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

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.


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')

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜