# switchimm

Model conversion function for

object`trackingIMM`

## Description

converts the `x`

= switchimm(`modelType1`

,`x1`

,`modelType2`

)`State`

or `StateCovariance`

properties
of the `trackingIMM`

object from `modelType1`

state definition to
`modelType2`

state definition.

`modelType1`

–– Specifies the string name of the current motion model.`x1`

–– Specifies`State`

or`StateCovariance`

corresponding to`modelType1`

.`modelType2`

–– Specifies the string name of the motion model to which`x1`

needs to be converted.

additionally lets you specify the size and type of the output. When not specified,
`x`

= switchimm(___,`x2`

)`x`

has the same data type and dimensionality as
`x1`

.

`x2`

specifies `State`

or
`StateCovariance`

corresponding to
`modelType2`

.

## Examples

### Convert State from Constant Acceleration to Constant Velocity

Convert state from constant acceleration model to constant velocity model using the `switchimm`

function.

**Initialization**

Set the current model to `'constacc'`

and the destination model to `'constvel'`

. The variable `x1`

defines the state in the current model.

modelType1 = 'constacc'; modelType2 = 'constvel'; x1 = single([1;2;3;4;5;6]);

**Conversion**

The `switchimm`

function converts the 2-D constant acceleration state input to a 2-D constant velocity state output. The output has the same dimensionality and data type as the input `x1`

.

x = switchimm(modelType1,x1,modelType2)

`x = `*4x1 single column vector*
1
2
4
5

### Convert State from Constant Acceleration to Constant Turn

Convert state from constant acceleration model to constant turn model using the `switchimm`

function. Specify `x2`

as an input parameter.

**Initialization**

Set the current model to `'constacc'`

and the destination model to `'constturn'`

. The variable `x1`

defines the state in the current model. The size and data type of the output is determined by the optional input `x2`

.

modelType1 = 'constacc'; modelType2 = 'constturn'; x1 = [1;2;3;4;5;6]; x2 = [0;0;0;0;0;0;0];

**Conversion**

The `switchimm`

function converts the 2-D constant acceleration state input to a 3-D constant turn model state output. The output has the same size and data type as the input `x2`

.

x = switchimm(modelType1,x1,modelType2,x2)

`x = `*7×1*
1
2
4
5
0
0
0

### Convert from Constant Velocity State to Constant Acceleration State

Convert state and state covariance from the constant velocity model to the constant acceleration model using the `switchimm`

function.

Set the current model to `'constvel'`

and the destination model to `'constacc'`

. Define the current state and state covariance.

modelType1 = 'constvel'; modelType2 = 'constacc'; x1 = ones(4,1); P1 = 1e4*eye(4);

Use the `switchimm`

function to convert the state and sate covariance from a constant velocity model to a constant acceleration model.

The function fills undefined state component with `0`

.

x2 = switchimm(modelType1,x1,modelType2)

`x2 = `*6×1*
1
1
0
1
1
0

The function fills undefined diagonal elements of covariance with `100`

.

P2 = switchimm(modelType1,P1,modelType2)

`P2 = `*6×6*
10000 0 0 0 0 0
0 10000 0 0 0 0
0 0 100 0 0 0
0 0 0 10000 0 0
0 0 0 0 10000 0
0 0 0 0 0 100

## Input Arguments

`modelType1`

— Current motion model

`'constvel'`

| `'constacc'`

| `'constturn'`

Current motion model, specified as:

`'constvel'`

–– Constant velocity motion model.`'constacc'`

–– Constant-acceleration motion model.`'constturn'`

–– Constant turn-rate motion model.

`x1`

— State or state covariance of current model

vector | matrix

State vector or state covariance matrix corresponding to the current model in
`modelType1`

, specified as an *L*-by-1 real vector
or an *L*-by-*L* real matrix.

The size of the state vector must fit the motion model. For example, if the
`modelType`

is `'constvel'`

, the state vector must
be of size 2, 4, or 6. Similarly, if the `modelType`

is
`'constacc'`

, the state vector must be of size 3, 6, or 9. If the
`modelType`

is `'constturn'`

, the state vector
must be of size 5, 7, 10, 15, 14, or 21. The relationship between model type, state
size, and the space dimension is given by the following table:

modelType1 | Supported Space Dimension | State size |
---|---|---|

`'constvel'` | 1-D, 2-D, 3-D | 2 ✕ Space dimension |

`'constacc'` | 1-D, 2-D, 3-D | 3 ✕ Space dimension |

`'constturn'` | 2-D and 3-D | 5 for 2-D space and 7 for 3-D space |

The `'constturn'`

model type supports only 2-D and 3-D spaces,
since a turn cannot be made in 1-D space. If the space dimension is computed to be 1-D,
that is, the state size equals 5 or 7, the function treats the output dimension as 2 and
the values corresponding to the second dimension are set to 0. For example, run the
following in the MATLAB^{®} command prompt:

switchimm('constvel',rand(2,1),'constturn')

**Data Types: **`single`

| `double`

`modelType2`

— Motion model to which `x1`

needs to be converted

`'constvel'`

| `'constacc'`

| `'constturn'`

`x1`

Motion model to which

needs to be
converted, specified as: `x1`

`'constvel'`

–– Constant velocity motion model.`'constacc'`

–– Constant-acceleration motion model.`'constturn'`

–– Constant turn-rate motion model.

`x2`

— Specify size and type of output state or state covariance

vector | matrix

The optional input `x2`

has the same size and data type as the
output state vector or the state covariance matrix, `x`

. The variable
`x2`

does not contain the actual output state information, but only
holds the size and the data type of the output state. For example, when
`x2`

is set to [0;0;0;0;0;0;0], the function determines the output
state vector to be a vector of size 7 with a data type of double.

The size of the state vector must fit the motion model. For example, if the
`modelType`

is `'constvel'`

, the state vector must
be of size 2, 4, or 6. Similarly, if the `modelType`

is
`'constacc'`

, the state vector must be of size 3, 6, or 9. The
relationship between model type, state size, and the space dimension is given by the
following table:

modelType1 | Supported Space Dimension | State size |
---|---|---|

`'constvel'` | 1-D, 2-D, 3-D | 2 ✕ Space dimension |

`'constacc'` | 1-D, 2-D, 3-D | 3 ✕ Space dimension |

`'constturn'` | 2-D and 3-D | 5 for 2-D space and 7 for 3-D space |

**Example: **[0;0;0;0;0;0;0]

**Data Types: **`single`

| `double`

## Output Arguments

`x`

— State or state covariance corresponding to `modelType2`

vector | matrix

`modelType2`

State vector or state covariance matrix, corresponding to the motion model specified
in `modelType2`

.

The relationship between model type, state size, and the space dimension is given by the following table:

modelType1 | Supported Space Dimension | State size |
---|---|---|

`'constvel'` | 1-D, 2-D, 3-D | 2 ✕ Space dimension |

`'constacc'` | 1-D, 2-D, 3-D | 3 ✕ Space dimension |

`'constturn'` | 2-D and 3-D | 5 for 2-D space and 7 for 3-D space |

**If **`x2`

** is
not specified:**

Given `modelType1`

and `x1`

, the function
determines the input state dimension based on the relationship specified in the table.
For example, if `modelType1`

is `'constvel'`

, and
`x1`

is a 4-by-1 vector, the input state dimension is given by 4/2,
which equals 2.

If `modelType1`

is `'constacc'`

and
`x1`

is a 6-by-1 vector, the input state dimension is given by 6/3,
which equals 2.

In this case when `x2`

is not specified, the output
`x`

has the same data type as `x1`

and the
dimension is calculated using `modelType1`

and
`x1`

.

**If **`x2`

** is
specified:**

The function calculates the output space dimension using
`modelType2`

and `x2`

. For example, if
`modelType2`

is `'constacc'`

and
`x2`

is a 6-by-1 vector, the output state dimension is given by
6/3, which equals 2.

The output `x`

has the same data type and dimensionality as
`x2`

.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2018b**

## MATLAB 명령

다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.

명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)