0

我创建了一个代码,它接受一个邻接矩阵作为用户的输入,并创建一个矩阵的 3d 散点图。我想在未连接的节点之间分配排斥力,在连接的节点之间分配吸引力,以便节点根据作用在它们上的净力发生位移。这必须是3d的。

4

1 回答 1

1

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

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

截屏

恐怕另一部分涉及更多,你必须证明你已经付出了一些努力,然后才会有人试图帮助你......

于 2011-07-14T22:43:41.720 回答