]> Creatis software - CreaPhase.git/blob - octave_packages/plot-1.1.0/gplot3.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / plot-1.1.0 / gplot3.m
1 ## Copyright (C) 2010 Soren Hauberg <soren@hauberg.org>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it
4 ## under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or (at
6 ## your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; see the file COPYING.  If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {} gplot3 (@var{a}, @var{xyz})
19 ## @deftypefnx {Function File} {} gplot3 (@var{a}, @var{xyz}, @var{line_style})
20 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} gplot3 (@var{a}, @var{xyz})
21 ## Plot a 3-dimensional graph defined by @var{A} and @var{xyz} in the
22 ## graph theory sense.  @var{A} is the adjacency matrix of the array to
23 ## be plotted and @var{xy} is an @var{n}-by-3 matrix containing the
24 ## coordinates of the nodes of the graph.
25 ##
26 ## The optional parameter @var{line_style} defines the output style for
27 ## the plot.  Called with no output arguments the graph is plotted
28 ## directly.  Otherwise, return the coordinates of the plot in @var{x}
29 ## and @var{y}.
30 ## @seealso{gplot, treeplot, etreeplot, spy}
31 ## @end deftypefn
32
33 function [x, y, z] = gplot3 (A, xyz, varargin)
34
35   if (nargin < 2)
36     print_usage ();
37   endif
38
39   if (length (varargin) == 0)
40     varargin {1} = "-";
41   endif
42
43   [i, j] = find (A);
44   xcoord = [xyz(i,1), xyz(j,1), NA(length(i),1)]'(:);
45   ycoord = [xyz(i,2), xyz(j,2), NA(length(i),1)]'(:);
46   zcoord = [xyz(i,3), xyz(j,3), NA(length(i),1)]'(:);
47
48   if (nargout == 0)
49     plot3 (xcoord, ycoord, zcoord, varargin {:});
50   else
51     x = xcoord;
52     y = ycoord;
53     z = zcoord;
54   endif
55
56 endfunction
57
58 %!demo
59 %! ## Define adjacency matrix of a graph with 5 nodes
60 %! A = [0, 1, 0, 0, 1;
61 %!      1, 0, 1, 1, 1;
62 %!      0, 1, 0, 1, 1;
63 %!      0, 1, 1, 0, 1;
64 %!      1, 1, 1, 1, 0 ];
65 %! 
66 %! ## Define 3D points of the nodes
67 %! xyz = [2,   1, 3/2;
68 %!        3,   2, 2;
69 %!        8/3, 3, 1;
70 %!        5/3, 3, 1;
71 %!        1,   2, 2 ];
72 %!
73 %! ## Plot the 3D graph
74 %! gplot3 (A, xyz);