std

Standard deviation of the elements of an array.

Category: Language Fundamentals > Data Types

Syntax

s = std(A)

Standard deviation along the first non-singleton dimension, normalized by N-1.

s = std(A, w)

Uses weight 0 (normalize by N-1) or 1 (normalize by N).

s = std(A, w, dim)

Operates along dimension dim.

s = std(___, 'omitnan')

Ignores NaN values.

Description

std is the square root of the variance, sqrt(var(A, w)). For a matrix it returns a row vector with one value per column. A single element has standard deviation 0, and an empty input gives NaN.

With the default NaN handling, any NaN in a column makes that column's result NaN; pass 'omitnan' to skip them.

Input arguments

A
Numeric or logical vector, matrix or N-D array.
w
0 for the sample estimate (default), 1 for the population value, or a vector of nonnegative weights.
dim
Dimension to operate along.

Output arguments

s
Standard deviation, with the operating dimension reduced to size 1.

Example

Sample, population and per column

x = [2 4 4 4 5 5 7 9];
std(x)
std(x, 1)
std([1 2; 3 8])
Output
ans = 2.1381
ans = 2
ans = 1×2

    1.4142    4.2426

See also

var mean median