# Statistical Built-In Functions in Matlab

Matlab → Basics → Arrays → Statistical Functions

Matlab has several useful built-in statistical functions. For example, consider a vector A, where `A=[5 9 2 4]` and we are interested in finding mean and variance of this data set. It can easily be done in Matlab using the commands `mean` and `var`. For example,

```>> A=[5 9 2 4]; >> mean(A) ans = 5 >> var(A) ans = 8.6667```

The next Table shows some more useful Matlab built-in statistical functions.

 Command Description Answer ```>> A=[5 9 2 4]; >> sum(A) ``` Calculate sum of the vector A. `20` ```>> A=[5 9 2 4]; >> mean(A) ``` Calculate mean (or average) of the vector A. Note that mean is used for arithmetic average. `5` ```>> A=[5 9 2 4]; >> geomean(A) ``` Calculate geometric mean of the vector A. `4.3559` ```>> A=[5 9 2 4]; >> sort(A) ``` Arrange the vector A in ascending order. `2 4 5 9` ```>> A=[5 9 2 4]; >> median(A) ``` Calculate median of the vector A. `4.5000` ```>> A=[5 9 2 4]; >> std(A)``` Calculate standard deviation of the vector A. `2.9439` ```>> A=[5 9 2 4]; >> var(A) ``` Calculate variance of the vector A. `8.6667` ```>> A=[5 9 2 4]; >> cumsum(A) ``` Calculate cumulative sum of the vector A. That is, 5, 5+9=14, 14+2=16, 16+4=20 `5 14 16 20` ```>> normcdf(0.3519) >> normcdf(-0.048) ``` The command `normcdf` returns the cumulative probability distribution function for a standardized normal distribution. ```0.6375 0.4809 ```
Posted