Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: plot a 3D graph
Posted:
Feb 27, 2013 12:45 PM
|
|
"ucla@stanford.edu" <krull.jan79@googlemail.com> wrote in message <dec00be6-159d-46d5-93a6-02f1671e1c5b@googlegroups.com>... > try this: > > function gplot4(A, xyz) > % GPLOT3(A, xyz) is nearly the same as GPLOT(A, xy) except > % that the xyz variable requires a third dimension. > % This function takes an adjacency matrix and visualizes it > % in 3D. > [d e] = size(A); > if d ~= e > error('A matrix must be square.'); > end > > [points f] = size(xyz); > if f ~= 3 > error('xyz matrix must be of width 3'); > end > > if points ~= d > error('Width of A must equal height of xyz.'); > end > > xp = []; > xq = []; > yp = []; > yq = []; > zp = []; > zq = []; > % c = []; > > > for i = 1:(d-1) > for j = 2:d > if A(i,j) ~= 0 > xp = [xp xyz(i, 1)]; > xq = [xq xyz(j, 1)]; > yp = [yp xyz(i, 2)]; > yq = [yq xyz(j, 2)]; > zp = [zp xyz(i, 3)]; > zq = [zq xyz(j, 3)]; > % c = [c full(A(i,j))]; > end > end > end > line([xp; xq], [yp; yq], [zp; zq]); > % > % > % numc = 10; > % cmap = autumn(numc); > % > % c = (c - min(c))/(max(c)-min(c)); > % c = floor((c*(numc-1))+1); > % %c = cmap(c,:); > % % line([xp; xq], [yp; yq], [zp; zq]); > % > % for n = 1:numel(xp) > % line([xp(n); xq(n)], [yp(n); yq(n)], [zp(n); zq(n)],'Color',cmap(c(n),:)); > % end > % > end > > Am Dienstag, 19. Februar 2013 22:40:20 UTC+1 schrieb Toan Cao: > > Hi everyone, > > > > > > > > I make a 3D graph of N nodes (vertices of 3D point cloud). I also have an adjacency matrix A (its size: NxN) for this graph where A(i,j)=1 if node i and node j connect together. If not , A(i,j)=0. > > > > So, i want to display this graph in 3D where two nodes (i, j) are linked by a line if A(i, j)=1. > > > > I know there is a function "gplot" for 2D graph, but i can not find the one for 3D graph. > > > > Do you know how to display my graph in 3D? Hope to get your help! > > > > > > > > Thanks in advance, > > > > Toan Thank you so much for your method I will try to apply it in my case.
Toan
|
|
|
|