]> Creatis software - CreaPhase.git/blob - octave_packages/m/sparse/spy.m
update packages
[CreaPhase.git] / octave_packages / m / sparse / spy.m
1 ## Copyright (C) 1998-2012 Andy Adler
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} spy (@var{x})
21 ## @deftypefnx {Function File} {} spy (@dots{}, @var{markersize})
22 ## @deftypefnx {Function File} {} spy (@dots{}, @var{line_spec})
23 ## Plot the sparsity pattern of the sparse matrix @var{x}.  If the argument
24 ## @var{markersize} is given as a scalar value, it is used to determine the
25 ## point size in the plot.  If the string @var{line_spec} is given it is
26 ## passed to @code{plot} and determines the appearance of the plot.
27 ## @seealso{plot}
28 ## @end deftypefn
29
30 function spy (x, varargin)
31
32   if (nargin < 1)
33     print_usage ();
34   endif
35
36   markersize = NaN;
37   if (numel (x) < 1000)
38     line_spec = "*";
39   else
40     line_spec = ".";
41   endif
42   for i = 1:length (varargin)
43     if (ischar (varargin{i}))
44       if (length (varargin{i}) == 1)
45         line_spec = [line_spec, varargin{i}];
46       else
47         line_spec = varargin{i};
48       endif
49     elseif (isscalar (varargin{i}))
50       markersize = varargin{i};
51     else
52       error ("spy: expected markersize or linespec");
53     endif
54   endfor
55
56   [i, j, s] = find (x);
57   [m, n] = size (x);
58
59   if (isnan (markersize))
60     plot (j, i, line_spec);
61   else
62     plot (j, i, line_spec, "markersize", markersize);
63   endif
64
65   axis ([0, n+1, 0, m+1], "ij");
66
67 endfunction
68
69
70 %!demo
71 %! clf;
72 %! spy (sprand (10,10, 0.2));
73
74 %% Mark graphical function as tested by demo block
75 %!assert (1);