Documentation

movstd

移动标准偏差

Description

example

m = movstd(A,k)returns an array of localk-观点standard deviation值。每个标准偏差都是通过长度的滑动窗口计算的k跨越相邻元素A。什么时候k很奇怪,窗口以当前位置的元素为中心。什么时候k即使是,窗口都集中在当前和以前的元素上。当没有足够的元素填充窗口时,窗口大小会在端点自动截断。当窗口被截断时,标准偏差仅在填充窗口的元素上进行。Mis the same size asA

  • 如果Ais a vector, thenmovstd沿矢量的长度运行。

  • 如果Ais a multidimensional array, thenmovstd沿着大小不等于1的第一个数组维度操作。

example

m = movstd(A,[KB KF])computes the standard deviation with a window of lengthKB+KF+1。The calculation includes the element in the current position,kbelements backward, andkf元素向前。

example

m = movstd(___,w)specifies a normalization factor for any of the previous syntaxes. Whenw = 0(默认),Mis normalized byk-1for window lengthk。什么时候w = 1,Mis normalized byk

example

m = movstd(___,w,dim)returns the array of sliding standard deviations along dimensiondimfor any of the previous syntaxes. Always specify the weightw从上一个指定时的语法dim。For example,movstd(a,k,0,2)operates along the columns of a matrixA,计算k- 每行的元素滑动标准偏差。归一化因子是默认因素,k-1

example

m = movstd(___,Nanflag)specifies whether to include or omitNaNvalues from the calculation for any of the previous syntaxes.movstd(a,k,'includeenan')includes allNaNvalues in the calculation whilemovstd(A,k,'omitnan')ignores them and computes the standard deviation over fewer points.

example

m = movstd(___,姓名,Value)specifies additional parameters for the standard deviation using one or more name-value pair arguments. For example, ifxis a time vector, thenmovstd(a,k,'samplepoints',x)computes the moving standard deviation relative to the times inx

Examples

collapse all

计算行矢量的三点中心运动标准偏差。当端点处的窗口中的元素少于三个元素时,请对可用元素进行标准偏差。

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movstd(a,3)
M =1×102.8284 2.0000 4.7258 4.3589 1.0000 1.0000 3.0551 2.6458 1.0000 0.7071

计算行矢量的三点尾随运动标准偏差。当端点处的窗口中的元素少于三个元素时,请对可用元素进行标准偏差。

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movstd(A,[2 0])
M =1×100 2.8284 2.0000 4.7258 4.3589 1.0000 1.0000 3.0551 2.6458 1.0000

计算行矢量的三点中心运动标准偏差,并按照窗口中的元素数量将每个标准偏差归一化。

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movstd(a,3,1)
M =1×102.0000 1.6330 3.8586 3.5590 0.8165 0.8165 2.4944 2.1602 0.8165 0.5000

计算矩阵每一行的三点中心运动标准偏差。窗口从第一行开始,水平滑到行的末端,然后移至第二行,依此类推。维度参数是两个,它将窗口滑过A。Always specify the normalization factor when specifying the dimension.

A = [4 8 6; -1 -2 -3; -1 3 4]; M = movstd(A,3,0,2)
M =3×32.8284 2.0000 1.4142 0.7071 1.0000 0.7071 2.8284 2.6458 0.7071

Compute the three-point centered moving standard deviation of a row vector containing twoNaN元素。

A = [4 8 NaN -1 -2 -3 NaN 3 4 5]; M = movstd(A,3)
M =1×102.8284 NaN NaN NaN 1.0000 NaN NaN NaN 1.0000 0.7071

重新计算标准偏差,但省略了NaN值。什么时候movstddiscardsNaNelements, it takes the standard deviation over the remaining elements in the window.

m = movstd(a,3,'omitnan')
M =1×102.8284 2.8284 6.3640 0.7071 1.0000 0.7071 4.2426 0.7071 1.0000 0.7071

计算数据中的3小时中心移动标准偏差A根据时间向量t

= [4 8 6 1 2 3]; k = hours(3); t = datetime(2016,1,1,0,0,0) + hours(0:5)
t =1x6 datetime arrayColumns 1 through 3 01-Jan-2016 00:00:00 01-Jan-2016 01:00:00 01-Jan-2016 02:00:00 Columns 4 through 6 01-Jan-2016 03:00:00 01-Jan-2016 04:00:00 01-Jan-2016 05:00:00
m = movstd(A,k,'SamplePoints',t)
M =1×62.8284 2.0000 4.7258 4.3589 1.0000 0.7071

计算行矢量的三点中心运动标准偏差,但丢弃了从输出中使用少于三个点的任何计算。换句话说,仅返回从完整的三元素窗口计算的标准偏差,丢弃端点计算。

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movstd(a,3,'端点','discard')
M =1×82.0000 4.7258 4.3589 1.0000 1.0000 3.0551 2.6458 1.0000

Input Arguments

collapse all

Input array, specified as a vector, matrix, or multidimensional array.

Data Types:单身的|double|logical

Window length, specified as a numeric or duration scalar. Whenkis a positive integer scalar, the centered standard deviation includes the element in the current position plus surrounding neighbors. For example, a three-point standard deviation defined by a window of length three results in the following calculation for a vectorA:

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|duration

Directional window length, specified as a numeric or duration row vector containing two elements. Whenkbkfare positive integer scalars, the calculation is overKB+KF+1元素。The calculation includes the element in the current position,kbelements before the current position, andkf当前位置之后的元素。例如,定向窗口定义的四点标准偏差[2 1]results in the following calculation for a vectorA:

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|duration

Weight, specified as one of these values:

  • 0— Normalize byk-1, wherek是窗口长度。如果k=1,重量是k

  • 1— Normalize byk

Data Types:单身的|double

Dimension to operate along, specified as a positive integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.

Dimensiondimindicates the dimension thatmovstd沿着指定的窗口滑动的方向运行。

Consider a two-dimensional input array,A

  • 如果DIM = 1, thenmovstd(A,k,0,1)starts with the first column and slides vertically over each row. The standard deviation is taken overk一次元素。然后它移至第二列并重复计算。这个过程一直持续到所有列都用尽。论点0specifies the default weight, which is required when specifyingdim

  • 如果DIM = 2, thenmovstd(a,k,0,2)从第一行开始,然后在每列中水平滑动。标准偏差已接管k一次元素。Then it moves to the second row and repeats the computation. This process continues until all rows are exhausted. The argument0specifies the default weight, which is required when specifyingdim

Data Types:double|单身的|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

NaN条件,指定为以下值之一:

  • 'includenan'- 包括NaNvalues from the input when computing the standard deviation, resulting in the outputNaN

  • 'omitnan'— Ignore allNaNvalues in the input. If a window contains onlyNaNvalues, thenmovstdreturnsNaN

姓名-Value Pair Arguments

Specify optional comma-separated pairs of姓名,Valuearguments.姓名is the argument name and价值是相应的值。姓名must appear inside quotes. You can specify several name and value pair arguments in any order as姓名1,Value1,...,NameN,ValueN

Example:m = movstd(A,k,'Endpoints','fill')

Method to treat leading and trailing windows, specified as the comma-separated pair consisting of'端点'和one of the following:

'端点'价值 Description
'shrink' Shrink the window size near the endpoints of the input to include only existing elements.
'discard' 不输出任何标准差时赢了吗dow does not completely overlap with existing elements.
'fill' Substitute nonexisting elements withNaN
numeric or logical scalar Substitute nonexisting elements with a specified numeric or logical value.

Data Types:double|单身的|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|logical|char|细绳

Sample points for computing standard deviations, specified as the comma-separated pair consisting of'SamplePoints'和矢量。样品点表示数据的位置A。样品点不需要均匀采样。默认情况下,示例点向量为[1 2 3 ... ]

移动窗口是相对于样品点定义的,该点必须对其进行排序并包含唯一的元素。例如,如果tis a vector of times corresponding to the input data, thenmovstd(rand(1,10),3,'SamplePoints',t)has a window that represents the time interval betweent(i)-1.5t(i)+1.5

什么时候the sample points vector has data type约会时间或者duration,然后移动的窗口长度必须具有类型duration

如果the sample points are nonuniformly spaced and the'端点'name-value pair is specified, then its value must be'shrink'

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|约会时间|duration

More About

collapse all

Standard Deviation

对于随机变量向量Amade up ofNscalar observations, the standard deviation is defined as

S = 1 N - 1 i = 1 N | A i - μ | 2 ,

在哪里μis the mean ofA:

μ = 1 N i = 1 N A i

The standard deviation is the square root of the variance. Some definitions of standard deviation use a normalization factor ofNinstead ofN-1,您可以通过设置指定w1

扩展功能

Introduced in R2016a