1 ## Copyright (C) 2004 Josep Mones i Teixidor
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{conn} = } conndef (@var{num_dims}, @var{type})
18 ## Creates a connectivity array.
20 ## @code{conn=conndef(num_dims,type)} creates a connectivity array
21 ## (@var{CONN}) of @var{num_dims} dimensions and which type is defined
22 ## by @var{type} as follows:
25 ## Neighbours touch the central element on a (@var{num_dims}-1)-dimensional
28 ## Neighbours touch the central element in any way. Equivalent to
29 ## @code{ones(repmat(3,1,@var{num_dims}))}.
36 ## Author: Josep Mones i Teixidor <jmones@puntbarra.com>
38 function conn = conndef(num_dims,conntype)
40 usage("conn=conndef(num_dims, type)");
43 error("conndef: num_dims must be > 0");
46 if(strcmp(conntype,"minimal"))
50 conn=[0,1,0;1,1,1;0,1,0];
52 conn=zeros(repmat(3,1,num_dims));
66 elseif(strcmp(conntype,"maximal"))
70 conn=ones(repmat(3,1,num_dims));
73 error("conndef: invalid type parameter.");
79 %! conndef(2,'minimal')
80 %! % Create a 2-D minimal connectivity array
82 %!assert(conndef(1,'minimal'), [1;1;1]);
84 %!assert(conndef(2,'minimal'), [0,1,0;1,1,1;0,1,0]);
90 %! C(:,:,2)=[0,1,0;1,1,1;0,1,0];
91 %! assert(conndef(3,'minimal'), C);
93 %!assert(conndef(1,'maximal'), ones(3,1));
94 %!assert(conndef(2,'maximal'), ones(3,3));
95 %!assert(conndef(3,'maximal'), ones(3,3,3));
96 %!assert(conndef(4,'maximal'), ones(3,3,3,3));
101 % Revision 1.3 2007/03/23 16:14:36 adb014
102 % Update the FSF address
104 % Revision 1.2 2007/01/04 23:41:47 hauberg
105 % Minor changes in help text
107 % Revision 1.1 2006/08/20 12:59:32 hauberg
108 % Changed the structure to match the package system
110 % Revision 1.2 2005/07/03 01:10:19 pkienzle
111 % Try to correct for missing newline at the end of the file
113 % Revision 1.1 2004/08/15 19:38:44 jmones
114 % conndef added: Creates a connectivity array