annotate scripts/sparse/gplot.m @ 5576:7e008607a86e

[project @ 2005-12-13 19:05:54 by jwe]
author jwe
date Tue, 13 Dec 2005 19:05:55 +0000
parents
children 6ada1581e8b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2005 Ivana Varekova
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
2 ##
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
5 ## the Free Software Foundation; either version 2 of the License, or
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
6 ## (at your option) any later version.
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
7 ##
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
11 ## GNU General Public License for more details.
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
12 ##
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
14 ## along with this program; if not, write to the Free Software
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
16 ## 02110-1301 USA
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
17
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
18 ## -*- texinfo -*-
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
19 ## @deftypefn {Function File} {} gplot (@var{a}, @var{xy})
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefnx {Function File} {} gplot (@var{a}, @var{xy}, @var{LineSpec})
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {[@var{x}, @var{y}] =} gplot (@var{a}, @var{xy})
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
22 ## Plots a graph defined by @var{A} and @var{xy} in the graph theory sense.
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
23 ## @var{A} is the adjacency matrix of the array to be plotted and @var{xy} is a
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
24 ## @var{n}-by-2 matrix containing the coordinates of the nodes of the graph.
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
25 ##
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
26 ## If defined, @var{LineStyle} defines the output style for the plot. Called
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
27 ## with no output arguments the graph is plotted directly. Called with output
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
28 ## arguments the coordinates of the plot are returned in @var{x} and @var{y},
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
29 ## rather than being plotted.
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
30 ## @end deftypefn
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
31 ## @seealso{treeplot,etreeplot,spy}
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
32
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
33 function [x, y] = gplot (A, xy, LineStyle)
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
34
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
35 if (nargin < 2 || nargin > 3 || nargout > 2)
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
36 error ("gplot: wrong number of input/output arguments");
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
37 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
38
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
39 if (nargin == 2)
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
40 LineStyle = "1;;";
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
41 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
42
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
43 [i,j] = find(A);
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
44 xcoord = [xy(i,1), xy(j,1), NaN * ones(length(i),1)]'(:);
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
45 ycoord = [xy(i,2), xy(j,2), NaN * ones(length(i),1)]'(:);
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
46
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
47 if (nargout == 0)
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
48 plot(xcoord,ycoord,LineStyle);
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
49 else
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
50 x = xcoord;
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
51 y = ycoord;
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
52 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
53
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
54 endfunction