# sample

Sample states from uniform state sampler

Since R2023b

## Syntax

``states = sample(sampler)``
``states = sample(sampler,numsamples)``

## Description

````states = sample(sampler)` returns a state sample selected using the uniform state sampling approach.```

example

````states = sample(sampler,numsamples)` returns the specified number of state samples.```

## Examples

collapse all

Use Default State Space as Input

Create a uniform state sampler with default properties. By default, the sampler uses the SE(2) state space as the configuration space for motion planning. The limits of the state variables [`x`, `y`, `theta`] in the default state space are `[-100 100; -100 100; -3.1416 3.1416]`. The values of `x` and `y` are in meters. `theta` is in radians.

`sampler = stateSamplerUniform;`

Check the bounds of the input state space.

`bounds = sampler.StateSpace.StateBounds`
```bounds = 3×2 -100.0000 100.0000 -100.0000 100.0000 -3.1416 3.1416 ```

Sample the input state space. Set the number of samples to select as 10.

`states = sample(sampler,10);`

Check the sampled state variables.

`disp(states)`
``` 62.9447 81.1584 -2.3437 82.6752 26.4718 -2.5287 -44.3004 9.3763 2.8746 92.9777 -68.4774 2.9568 91.4334 -2.9249 1.8867 -71.6227 -15.6477 2.6121 58.4415 91.8985 0.9785 -92.8577 69.8259 2.7269 35.7470 51.5480 1.5276 -21.5546 31.0956 -2.0660 ```

Use Custom State Space as Input

Define a custom SE(2) state space by specifying the limits of the state variables [`x`, `y`, `theta`]. The values of `x` and `y` are in meters. `theta` is in radians.

`ss = stateSpaceSE2([-1 1; -2 2; -pi/2 pi/2]);`

Create a uniform state sampler with the custom state space as input.

`sampler = stateSamplerUniform(ss);`

Sample the input state space. Set the number of samples to select as 10.

`states = sample(sampler,10);`

Check the sampled state variables.

`disp(states)`
``` 0.4121 -1.8727 -0.7008 -0.9077 -1.6115 1.0162 0.3897 -0.7316 1.4144 -0.9311 -0.2450 -0.3721 0.5310 1.1808 -0.9837 -0.0205 -0.2177 0.4597 0.4187 1.0187 -0.7036 0.3594 0.6204 -1.0599 -0.7620 -0.0065 1.4443 -0.3192 0.3411 -0.8677 ```

## Input Arguments

collapse all

State sampler object, specified as a `stateSamplerUniform` object.

Number of samples, specified as a positive integer.

Data Types: `double`

## Output Arguments

collapse all

State samples, returned as an M-by-N matrix of real values. M is the number of states. N is the number of state variables. Each row of the matrix specifies the state variables corresponding to the input state space model. For example, for the SE(2) state space model, N is 3, and each row is of the form [`x`, `y`, `theta`].

Data Types: `double`

## Version History

Introduced in R2023b