# conndef

Create connectivity array

## Syntax

• ``conn = conndef(num_dims,type)``
example

## Description

example

````conn = conndef(num_dims,type)` returns the connectivity array defined by `type` for `num_dims` dimensions. Several Image Processing Toolbox™ functions use `conndef` to create the default connectivity input argument. Code Generation support: Yes.MATLAB Function Block support: Yes.```

## Examples

collapse all

### Create 2-D Connectivity Array with Minimal Connectivity

`conn1 = conndef(2,'minimal')`
```conn1 = 0 1 0 1 1 1 0 1 0```

### Create 2-D Connectivity Array with Maximal Connectivity

`conn2 = conndef(2,'maximal')`
```conn2 = 1 1 1 1 1 1 1 1 1```

### Create 3-D Connectivity Array with Minimal Connectivity

`conndef(3,'minimal')`
```ans(:,:,1) = 0 0 0 0 1 0 0 0 0 ans(:,:,2) = 0 1 0 1 1 1 0 1 0 ans(:,:,3) = 0 0 0 0 1 0 0 0 0```

## Input Arguments

collapse all

### `num_dims` — Number of dimensionsnumeric scalar

Number of dimensions, specified as a numeric scalar.

Example: `conn1 = conndef(2,'minimal')`

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

### `type` — Type of neighborhood connectivity`'minimal'` | `'maximal'`

Type of neighborhood connectivity, specified as the string `'minimal'` or `'maximal'`

Value

Description

`'minimal'`

Defines a neighborhood whose neighbors are touching the central element on an (`N`-1)-dimensional surface, for the `N`-dimensional case.

`'maximal'`

Defines a neighborhood including neighbors that touch the central element in any way; it is `ones(repmat(3,1,NUM_DIMS))`.

Example: `conn1 = conndef(2,'minimal')`

Data Types: `char`

## Output Arguments

collapse all

### `conn` — Connectivity matrix3-by-3-by...-3 logical array

Connectivity matrix, returned as a 3-by-3-....-by-3 logical array.

expand all

### Code Generation

This function supports the generation of C code using MATLAB® Coder™. For more information, see Code Generation for Image Processing.

When generating code, the `num_dims` and `type` arguments must be compile-time constants.

### MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.