annotate scripts/image/colormap.m @ 16946:92f42d9f2ae4

colormap.m: Add demos, tests, and warning when using deprecated syntax. * scripts/image/colormap.m: Add warning when using syntax 'colormap ("name")'. Add %!demos and %!test blocks. Shuffle documentation string a bit.
author Rik <rik@octave.org>
date Wed, 10 Jul 2013 12:43:29 -0700
parents 7268845c0a1e
children 24bb7dc754ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1 ## Copyright (C) 1994-2012 John W. Eaton
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
2 ## Copyright (C) 2012 Carnë Draug
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
18 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
19
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
20 ## -*- texinfo -*-
14246
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefn {Function File} {@var{cmap} =} colormap ()
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
22 ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map})
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default")
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
24 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("list")
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
25 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("register", "@var{name}")
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
26 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("unregister", "@var{name}")
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
27 ## Query or set the current colormap.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
28 ##
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
29 ## With no input arguments, @code{colormap} returns the current color map.
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
30 ##
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
31 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
32 ## colormap should be an @var{n} row by 3 column matrix. The columns
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
33 ## contain red, green, and blue intensities respectively. All entries
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
34 ## must be between 0 and 1 inclusive. The new colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
35 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
36 ## @code{colormap ("default")} restores the default colormap (the
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
37 ## @code{jet} map with 64 entries). The default colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
38 ##
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
39 ## @code{colormap ("list")} returns a cell array with all of the available
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
40 ## colormaps. The options "register" and "unregister" will add or remove
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
41 ## the colormap @var{name} from this list.
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
42 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
43 ## @seealso{jet}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
44 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
45
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3106
diff changeset
46 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
47 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
48 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
49
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
50 function cmap = colormap (map, name)
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
51
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
52 if (nargin > 2)
5923
611e30b984b3 [project @ 2006-08-14 18:29:18 by jwe]
jwe
parents: 5443
diff changeset
53 print_usage ();
1062
1b3a87031641 [project @ 1995-01-24 02:54:50 by jwe]
jwe
parents: 1024
diff changeset
54 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
55
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
56 persistent map_list = cell ();
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
57 persistent do_warning = true;
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
58
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
59 if (nargin == 1)
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
60
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
61 if (ischar (map))
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
62 if (strcmp (map, "default"))
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
63 map = jet (64);
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
64 elseif (strcmp (map, "list"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
65 cmap = map_list;
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
66 return;
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
67 else
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
68 ## FIXME: This syntax is deprecated. It is no longer mentioned in
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
69 ## documentation and should probably be removed in Octave 3.12.
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
70 if (do_warning)
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
71 warning (["colormap: deprecated syntax 'colormap (\"%s\")'. " ...
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
72 "Use 'colormap (%s (64))'"], map, map);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
73 do_warning = false;
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
74 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 5923
diff changeset
75 map = feval (map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
76 endif
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
77 endif
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
78
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
79 if (! isempty (map))
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
80 if (! (isnumeric (map) && isreal (map)
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
81 && ndims (map) == 2 && columns (map) == 3))
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
82 error ("colormap: MAP must be a real-valued N x 3 ([R,G,B]) matrix");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
83 endif
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
84 if (any (map(:) < 0) || any (map(:) > 1))
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
85 error ("colormap: all MAP values must be in the range [0,1]");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
86 endif
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
87 ## Set the new color map
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 5923
diff changeset
88 set (gcf (), "colormap", map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
89 endif
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
90
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
91 elseif (nargin == 2)
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
92 if (! ischar (map) || ! any (strcmp (map, {"register", "unregister"})))
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
93 print_usage ();
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
94 elseif (! ischar (name))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
95 error ("colormap: to register/unregister a colormap, NAME must be a string");
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
96 elseif (strcmp (map, "register"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
97 map_list{end+1} = name;
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
98 elseif (strcmp (map, "unregister"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
99 map_list(strcmp (name, map_list)) = [];
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
100 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
101 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
102
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
103 ## Return current color map.
7108
60a1165732f9 [project @ 2007-11-06 22:05:18 by jwe]
jwe
parents: 7017
diff changeset
104 if (nargout > 0 || (nargout == 0 && nargin == 0))
6762
721953d49b19 [project @ 2007-06-27 18:20:19 by jwe]
jwe
parents: 6257
diff changeset
105 cmap = get (gcf (), "colormap");
721953d49b19 [project @ 2007-06-27 18:20:19 by jwe]
jwe
parents: 6257
diff changeset
106 endif
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
107
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
108 endfunction
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
109
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
110
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
111 %!demo
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
112 %! ## Create an image for displaying a colormap
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
113 %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
114 %! axis ([1, 64, 0, 1], "ticy", "xy");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
115 %! ## Show 'jet' colormap
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
116 %! colormap (jet (64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
117 %! title "colormap (jet (64))"
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
118 %! disp ("Press a key to continue");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
119 %! pause ();
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
120 %! ## Show 'colorcube' colormap
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
121 %! colormap (colorcube (64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
122 %! title "colormap (colorcube (64))"
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
123
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
124 %!test
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
125 %! figure ("visible", "off");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
126 %! cmaptst = [0 1 0; 1 0 1; 1 1 1];
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
127 %! cmap = colormap (cmaptst);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
128 %! assert (cmap, cmaptst);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
129 %! cmap = colormap ();
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
130 %! assert (cmap, cmaptst);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
131 %! cmap = (get (gcf, "colormap"));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
132 %! assert (cmap, cmaptst);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
133 %! colormap ("default");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
134 %! assert (colormap (), jet (64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
135 %! colormap ("ocean");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
136 %! assert (colormap, ocean (64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
137 %! close (); # done with temp. figure
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
138
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
139 %!test
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
140 %! cmaplst = colormap ("list");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
141 %! assert (iscell (cmaplst));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
142 %! colormap ("register", "__mycmap__");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
143 %! cmaplst2 = colormap ("list");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
144 %! assert (numel (cmaplst2), numel (cmaplst) + 1);
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
145 %! assert (any (strcmp (cmaplst2, "__mycmap__")));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
146 %! colormap ("unregister", "__mycmap__");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
147 %! cmaplst2 = colormap ("list");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
148 %! assert (numel (cmaplst2), numel (cmaplst));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
149 %! assert (! any (strcmp (cmaplst2, "__mycmap__")));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
150 %! ## Unregister again and verify that nothing has happened
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
151 %! colormap ("unregister", "__mycmap__");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
152 %! cmaplst3 = colormap ("list");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
153 %! assert (isequal (cmaplst2, cmaplst3));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
154
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
155 ## Test input validation
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
156 %!error colormap (1,2,3)
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
157 %!error <MAP must be a real-valued N x 3> colormap ({1,2,3})
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
158 %!error <MAP must be a real-valued N x 3> colormap ([1 i 1])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
159 %!error <MAP must be a real-valued N x 3> colormap (ones(3,3,3))
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
160 %!error <MAP must be a real-valued N x 3> colormap ([1 0 1 0])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
161 %!error <all MAP values must be in the range> colormap ([-1 0 0])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
162 %!error <all MAP values must be in the range> colormap ([2 0 0])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
163 %!error colormap ("invalid", "name")
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
164 %!error <NAME must be a string> colormap ("register", 1)
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
165