# getTrackVelocities

Obtain updated track velocities and velocity covariance matrix

## Syntax

## Description

returns velocities of tracked objects.`velocity`

= getTrackVelocities(`tracks`

,`velocitySelector`

)

`[`

also returns the track velocity covariance matrices.`velocity`

,`velocityCovariances`

]
= getTrackVelocities(`tracks`

,`velocitySelector`

)

## Examples

### Find Velocity of 3-D Constant-Acceleration Object

Create an extended Kalman filter tracker for 3-D constant-acceleration motion.

`tracker = radarTracker('FilterInitializationFcn',@initcaekf);`

Initialize the tracker with one detection.

```
detection = objectDetection(0,[10;-20;4],'ObjectClassID',3);
tracks = tracker(detection,0);
```

Add a second detection at a later time and at a different position.

```
detection = objectDetection(0.1,[10.3;-20.2;4],'ObjectClassID',3);
tracks = tracker(detection,0.2);
```

Obtain the velocity vector from the track state.

velocitySelector = [0 1 0 0 0 0 0 0 0; 0 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 0 1 0]; velocity = getTrackVelocities(tracks,velocitySelector)

`velocity = `*1×3*
1.0093 -0.6728 0

### Velocity and Covariance of 3-D Constant-Acceleration Object

Create an extended Kalman filter tracker for 3-D constant-acceleration motion.

`tracker = radarTracker('FilterInitializationFcn',@initcaekf);`

Initialize the tracker with one detection.

```
detection = objectDetection(0,[10;-20;4],'ObjectClassID',3);
tracks = step(tracker,detection,0);
```

Add a second detection at a later time and at a different position.

```
detection = objectDetection(0.1,[10.3;-20.2;4.3],'ObjectClassID',3);
tracks = step(tracker,detection,0.2);
```

Obtain the velocity vector from the track state.

velocitySelector = [0 1 0 0 0 0 0 0 0; 0 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 0 1 0]; [velocity,velocityCovariance] = getTrackVelocities(tracks,velocitySelector)

`velocity = `*1×3*
1.0093 -0.6728 1.0093

`velocityCovariance = `*3×3*
70.0685 0 0
0 70.0685 0
0 0 70.0685

## Input Arguments

`tracks`

— Object tracks

array of `objectTrack`

objects | array of structures

Object tracks, specified as an array of `objectTrack`

objects or an
array of structures containing sufficient information to obtain the track
velocity information. At a minimum, these structures must contain a
`State`

column vector field and a positive-definite
`StateCovariance`

matrix field. For a sample
track structure, see `toStruct`

.

`velocitySelector`

— Velocity selection matrix

*D*-by-*N* real-valued matrix.

Velocity selector, specified as a
*D*-by-*N* real-valued matrix of ones
and zeros. *D* is the number of dimensions of the tracker.
*N* is the size of the state vector. Using this matrix,
the function extracts track velocities from the state vector. Multiply the
state vector by velocity selector matrix returns velocities. The same
selector is applied to all object tracks.

## Output Arguments

`velocity`

— Velocities of tracked objects

real-valued *1*-by-*D* vector | real-valued *M*-by-*D* matrix

Velocities of tracked objects at last update time, returned as a
*1*-by-*D* vector or a real-valued
*M*-by-*D* matrix.
*D* represents the number of velocity elements.
*M* represents the number of tracks.

`velocityCovariances`

— Velocity covariance matrices of tracked objects

real-valued *D*-by-*D*-matrix | real-valued
*D*-by-*D*-by-*M*
array

Velocity covariance matrices of tracked objects, returned as a real-valued
*D*-by-*D*-matrix or a real-valued
*D*-by-*D*-by-*M*
array. *D* represents the number of velocity elements.
*M* represents the number of tracks. Each
*D*-by-*D* submatrix is a velocity
covariance matrix for a track.

## More About

### Velocity Selector for 2-Dimensional Motion

Show the velocity selection matrix for two-dimensional motion when the state consists of the position and velocity.

$$\left[\begin{array}{cccc}0& 1& 0& 0\\ 0& 0& 0& 1\end{array}\right]$$

### Velocity Selector for 3-Dimensional Motion

Show the velocity selection matrix for three-dimensional motion when the state consists of the position and velocity.

$$\left[\begin{array}{cccccc}0& 1& 0& 0& 0& 0\\ 0& 0& 0& 1& 0& 0\\ 0& 0& 0& 0& 0& 1\end{array}\right]$$

### Velocity Selector for 3-Dimensional Motion with Acceleration

Show the velocity selection matrix for three-dimensional motion when the state consists of the position, velocity, and acceleration.

$$\left[\begin{array}{ccccccccc}0& 1& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 1& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 1& 0\end{array}\right]$$

## Extended Capabilities

### C/C++ Code Generation

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

## Version History

**Introduced in R2021a**

## See Also

### Functions

### Objects

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# 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)