# 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8140014,"math_prob":0.9564719,"size":1214,"snap":"2020-24-2020-29","text_gpt3_token_len":320,"char_repetition_ratio":0.15371901,"word_repetition_ratio":0.019900497,"special_character_ratio":0.27512357,"punctuation_ratio":0.1322314,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.984589,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-06-03T15:53:19Z\",\"WARC-Record-ID\":\"<urn:uuid:498c6591-95df-48e5-b8ea-b935a7c97eaa>\",\"Content-Length\":\"75604\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:032d8c9c-8cc6-43c3-b9c2-5af44a5bd842>\",\"WARC-Concurrent-To\":\"<urn:uuid:9760bb95-e485-455d-8fbe-0a193c973064>\",\"WARC-IP-Address\":\"104.110.193.39\",\"WARC-Target-URI\":\"https://fr.mathworks.com/help/stats/paretotails.nsegments.html\",\"WARC-Payload-Digest\":\"sha1:5M3F636LMJ2XBBOBYTAZSRONUKCKRSSM\",\"WARC-Block-Digest\":\"sha1:6SGPTHXLBZJPQ5K6RCXQ2SGK7XWUQ66C\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347435238.60_warc_CC-MAIN-20200603144014-20200603174014-00511.warc.gz\"}"}