main Content

movsum

moving sum

Description

例子

m =movsum(一个,,,,kreturns an array of localk-point sums, where each sum is calculated over a sliding window of lengthkacross neighboring elements of一个。什么时候kis odd, the window is centered about the element in the current position. Whenk甚至,窗口集中当前呢and previous elements. The window size is automatically truncated at the endpoints when there are not enough elements to fill the window. When the window is truncated, the sum is taken over only the elements that fill the window.mis the same size as一个

  • 如果一个是一个向量,然后movsumoperates along the length of the vector.

  • 如果一个is a multidimensional array, thenmovsumoperates along the first array dimension whose size does not equal 1.

例子

m =movsum(一个,,,,[kb kf]用长度窗口计算总和KB+kf+1that includes the element in the current position,KBelements backward, andKFelements forward.

例子

m =movsum(___,,,,暗淡returns the array of sliding sums along dimension暗淡对于以前的任何语法。例如,如果一个is a matrix, thenmovsum(a,k,2)operates along the columns of一个,,,,computing thek- 每行的元素滑动总和。

例子

m =movsum(___,,,,nanflagspecifies whether to include or omit来自任何先前语法的计算值。movsum(A,k,'includenan')包括全部values in the calculation whilemovsum(a,k,'omitnan')ignores them and computes the sum over fewer points.

例子

m =movsum(___,,,,名称,价值specifies additional parameters for the sum using one or more name-value pair arguments. For example, ifXis a time vector, thenmovsum(A,k,'SamplePoints',x)计算移动总和一个相对于时间X

Examples

全部收缩

计算行矢量的三点中心运动总和。当端点处的窗口中的元素中少于三个元素时,请在可用的元素上取出总和。

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movsum(a,3)
m =1×1012 18 13 3 -6 -6 -1 6 12 9

Compute the three-point trailing moving sum of a row vector. When there are fewer than three elements in the window at the endpoints,movsumtakes the sum over the number of elements that are available.

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m =movsum(A,[2 0])
m =1×104 12 18 13 3 -6 -6 -1 6 12

Compute the three-point centered moving sum for each row of a matrix. The window starts on the first row, slides horizontally to the end of the row, then moves to the second row, and so on. The dimension argument is two, which slides the window across the columns of一个

a = [4 8 6;-1 -2 -3;-1 3 4]
a =3×34 8 6 -1 -2 -3 -1 3 4
m = movsum(a,3,2)
m =3×312 18 14 -3 -6 -5 2 6 7

Compute the three-point centered moving sum of a row vector containing two元素。

a =[4 8 NaN -1 -2 -3 NaN 3 4 5]; M = movsum(A,3)
m =1×1012 NaN NaN NaN -6 NaN NaN NaN 12 9

重新计算总和,但省略了values. Whenmovsumdiscardselements, it takes the sum over the remaining elements in the window.

m = movsum(a,3,'omitnan'
m =1×1012 12 7 -3 -6 -5 0 7 12 9

Compute a 3-hour centered moving sum of the data in一个according to the time vectort

a = [4 8 6 -1 -2 -2 -3];k =小时(3);t = dateTime(16,1,1,1,0,0) +小时(0:5)
t=1x6 datetime列1至3 01-JAN-0016 00:00:00 01-JAN-0016 01:00:00 01-JAN-0016 02:00:00列4到6 01-JAN-20016 03:00:00:00 01--Jan-0016 04:00:00 01-Jan-0016 05:00:00
m =movsum(A,k,“样本点”,,,,t)
m =1×612 18 13 3 -6 -5

Compute the three-point centered moving sum of a row vector, but discard any calculation that uses fewer than three points from the output. In other words, return only the sums computed from a full three-element window, discarding endpoint calculations.

a = [4 8 6 -1 -1 -2 -3 -1 3 4 5];m = movsum(a,3,'Endpoints',,,,'discard'
m =1×818 13 3 3 -6 -6 -1 6 12

输入参数

全部收缩

输入阵列,指定为向量,矩阵或多维数组。

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|逻辑

窗口长度,指定为数字或持续时间标量。什么时候k是一个正整数标量,中心总和包括当前位置中的元素以及周围的邻居。例如,由长度窗口定义的三分总和在以下计算中的三个结果中,对向量计算一个

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|期间

定向窗口长度,指定为包含两个元素的数字或持续时间行矢量。什么时候KBandKF是正整数标量,计算已经结束KB+kf+1元素。计算包括当前位置中的元素,KB当前位置之前的要素,KF当前位置之后的元素。例如,由方向窗口定义的四点总和[2 1]导致矢量的以下计算一个

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|期间

维操作,指定为是e integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.

Dimension暗淡表示维度movsumoperates along, that is, the direction in which the specified window slides.

Consider a two-dimensional input array,一个

  • 如果暗淡= 1, 然后movsum(a,k,1)starts with the first column and slides vertically over each row. The sum is computed overk一次元素。然后它移至第二列并重复计算。这个过程一直持续到所有列都用尽。

  • 如果暗淡= 2, 然后movsum(a,k,2)从第一行开始,然后在每列中水平滑动。总和计算k一次元素。然后它移至第二行并重复计算。这个过程一直持续到所有行耗尽为止。

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

condition, specified as one of these values:

  • 'includeenan'-Includevalues when computing the sum, resulting in

  • 'omitnan'-Ignore all输入中的值。如果窗口仅包含然后movsumreturns 0.

名称值参数

指定可选的逗号分隔对名称,价值arguments.Name是参数名称和Valueis the corresponding value.Name必须出现在引号中。您可以按任何顺序指定几个名称和值对参数Name1,Value1,...,NameN,ValueN

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

处理前导和尾随窗户的方法,指定为逗号分隔对'Endpoints'以及以下一个:

'Endpoints'Value Description
'shrink' 收缩输入端点附近的窗口大小,仅包括现有元素。
'discard' 当窗口没有完全与现有元素重叠时,请勿输出任何总和。
'fill' 用不使用的元素代替
numeric or logical scalar 用不使用的元素代替a specified numeric or logical value.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|逻辑|char|string

计算总和的样本点,指定为逗号分隔对“样本点”and a vector. The sample points represent the location of the data in一个。Sample points do not need to be uniformly sampled. By default, the sample points vector is[1 2 3 ... ]

moving windows are defined relative to the sample points, which must be sorted and contain unique elements. For example, ift是与输入数据相对应的时间的向量,然后movsum(rand(1,10),3,“样本点”,t)有一个窗口,表示之间的时间间隔t(i)-1.5andt(i)+1.5

当示例点向量具有数据类型时datetimeor期间, 然后the moving window length must have type期间

如果样品点不均匀,则'Endpoints'name-value pair is specified, then its value must be'shrink'

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|datetime|期间

Extended Capabilities

在R2016a中引入