# nsegments

Number of segments in piecewise distribution

## Syntax

``n = nsegments(pd)``

## Description

example

````n = nsegments(pd)` returns the number of segments in the piecewise distribution object `pd`.```

## Examples

collapse all

Generate a sample data set and fit a piecewise distribution with a Pareto tail to the data by using `paretotails`. Find the number of segments in the fitted distribution by using the object function `nsegments`.

Generate a sample data set containing 10% outliers in the right tail.

```rng('default'); % For reproducibility right_tail = exprnd(5,100,1); center = randn(900,1); x = [center;right_tail];```

Create a `paretotails` object by fitting a piecewise distribution to `x`. Specify the boundaries of the tails using the lower and upper tail cumulative probabilities. Pass in 0 and 0.9 so that a fitted object does not contain a lower tail segment, and consists of the empirical distribution for the lower 90% of the data set and a generalized Pareto distribution (GPD) for the upper 10% of the data set.

`pd = paretotails(x,0,0.9)`
```pd = Piecewise distribution with 2 segments -Inf < x < 1.73931 (0 < p < 0.9): interpolated empirical cdf 1.73931 < x < Inf (0.9 < p < 1): upper tail, GPD(0.643752,1.62246) ```

Return the number of segments in `pd` by using the `nsegments` function.

`n = nsegments(pd)`
```n = 2 ```

You can also get the number of segments by using the `NumSegments` property. Access the `NumSegments` property by using dot notation.

`pd.NumSegments`
```ans = 2 ```

## Input Arguments

collapse all

Piecewise distribution with Pareto tails, specified as a `paretotails` object.