## Introduction to Matlab Standard Deviation

Standard deviation is used to measure the spread in statistics. Spread, also referred to as “Dispersement”, tells us how much our data points are spread out around the average or mean. A ‘Bell curve’ is used to study the standard deviation in Statistics. In Matlab, we use the ‘std’ function to compute the standard deviation of a vector or a data set. In today’s world, the standard deviation is extensively used in data analytics to create sophisticated Artificial Intelligence based algorithms.

**Syntax of standard deviation function:**

`SD = std (X)`

`SD = std (X, w)`

**Explanation:**

- SD = std (X) is used to compute the standard deviation of the elements of ‘X’. Here, ‘X’ can be a vector, matrix, or multidimensional array.
- SD = std (X, w) is used to compute the standard deviation of the elements of ‘X’ with a weightage of ‘w’.

Please note that, by default, the standard deviation will be normalized to N-1, N being our number of observations.

### Examples of Matlab Standard Deviation

Given below are the examples of Matlab Standard Deviation:

#### Example #1

In this example, we will use the std function to compute the standard deviation of elements of an array.

Below are the steps to be followed:

- Initialize the input array.
- Pass this input array as an argument to the standard deviation function.

**Code:**

X = [7 -5 11 2 6 5 -8 0 17 5] [Initializing the input array with 10 elements]

SD = std (X)

[Using the std function to compute standard deviation for the elements of the input array]

**Input:**

**Output:**

As we can see in the output, 7.2877 is the standard deviation of the elements of our input array.

#### Example #2

This example will use the std function to compute the standard deviation of 3 x 3 matrix elements.

4.5 (7,690 ratings)

View Course

Below are the steps to be followed:

- Initialize the input 3 x 3 matrix.
- Pass this input matrix as an argument to the standard deviation function.

Please note that, for a matrix, the std function will compute the standard deviation of elements along each column.

**Code:**

X = [5 -5 1; 0 4 3; 8 10 4] [Initializing the input 3 x 3 matrix]

SD = std (X)

[Using the std function to compute standard deviation for the elements of the input matrix]

**Input:**

**Output:**

As we can see in the output, we have obtained the standard deviation of the elements of our input matrix along with the columns.

#### Example #3

In this example, we will use the std function to compute the standard deviation of elements of a 3-Dimensional array.

Below are the steps to be followed:

- Initialize the input 3-Dimensional array.
- Pass this input 3D array as an argument to the standard deviation function.

**Code:**

X (:, :, 1) = [1 5 3; 2 0 1; 2 2 2];

X (:, :, 2) = [19 3 3; 5 1 3; 3 5 1];

X (:, :, 3) = [0 4 1; 2 -3 1; 2 4 7];

[Initializing the input 3 x 3 matrix]

SD = std (X)

[Using the std function to compute standard deviation for the elements of the input 3D array]

**Input:**

**Output:**

As we can see in the output, we have obtained the standard deviation of our 3-D input array elements along with the columns.

In the above 3 examples, we have not provided any weightage while computing the standard deviation.

Let us now see how to assign weightage in the std function.

#### Example #4

In this example, we will use the std function to compute the standard deviation of a 3 x 3 matrix elements and assign some weightage to it.

Below are the steps to be followed:

- Initialize the input 3 x 3 matrix.
- Initialize the weightage vector.
- Pass the input matrix and weightage vector as arguments to the standard deviation function.

**Code:**

X = [2 15 4; 1 6 4; 1 -5 2];

[Initializing the input 3 x 3 matrix]

w = [0.7 1 1.5];

[Initializing the weightage vector]

SD = std (X, w)

[Using the std function to compute standard deviation for the elements of the input matrix. We have also passed weightage vector ‘w’ as the second argument]

**Input:**

**Output:**

As we can see in the output, we have obtained the standard deviation of our 3 x 3 matrix elements with assigned weightage.

### Conclusion

We use the std function to compute the standard deviation of an array, vector, or matrix elements. The standard deviation, by default, will be normalized to N-1, N being our number of observations.

### Recommended Articles

This is a guide to Matlab Standard Deviation. Here we discuss the introduction and examples of Matlab standard deviation, respectively. You may also have a look at the following articles to learn more –