<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Statistics on Sliding Windows of Data (GNU Octave (version 5.1.0))</title> <meta name="description" content="Statistics on Sliding Windows of Data (GNU Octave (version 5.1.0))"> <meta name="keywords" content="Statistics on Sliding Windows of Data (GNU Octave (version 5.1.0))"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <link href="index.html#Top" rel="start" title="Top"> <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="Statistics.html#Statistics" rel="up" title="Statistics"> <link href="Basic-Statistical-Functions.html#Basic-Statistical-Functions" rel="next" title="Basic Statistical Functions"> <link href="Descriptive-Statistics.html#Descriptive-Statistics" rel="prev" title="Descriptive Statistics"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smalllisp {margin-left: 3.2em} kbd {font-style: oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nolinebreak {white-space: nowrap} span.roman {font-family: initial; font-weight: normal} span.sansserif {font-family: sans-serif; font-weight: normal} ul.no-bullet {list-style: none} --> </style> <link rel="stylesheet" type="text/css" href="octave.css"> </head> <body lang="en"> <a name="Statistics-on-Sliding-Windows-of-Data"></a> <div class="header"> <p> Next: <a href="Basic-Statistical-Functions.html#Basic-Statistical-Functions" accesskey="n" rel="next">Basic Statistical Functions</a>, Previous: <a href="Descriptive-Statistics.html#Descriptive-Statistics" accesskey="p" rel="prev">Descriptive Statistics</a>, Up: <a href="Statistics.html#Statistics" accesskey="u" rel="up">Statistics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <hr> <a name="Statistics-on-Sliding-Windows-of-Data-1"></a> <h3 class="section">26.2 Statistics on Sliding Windows of Data</h3> <p>It is often useful to calculate descriptive statistics over a subsection (i.e., window) of a full dataset. Octave provides the function <code>movfun</code> which will call an arbitrary function handle with windows of data and accumulate the results. Many of the most commonly desired functions, such as the moving average over a window of data (<code>movmean</code>), are already provided. </p> <a name="XREFmovfun"></a><dl> <dt><a name="index-movfun"></a><em><var>y</var> =</em> <strong>movfun</strong> <em>(<var>fcn</var>, <var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movfun-1"></a><em><var>y</var> =</em> <strong>movfun</strong> <em>(<var>fcn</var>, <var>x</var>, <var>[<var>nb</var>, <var>na</var></var>])</em></dt> <dt><a name="index-movfun-2"></a><em><var>y</var> =</em> <strong>movfun</strong> <em>(…, "<var>property</var>", <var>value</var>)</em></dt> <dd> <p>Apply function <var>fcn</var> to a moving window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <var>fcn</var> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movfun</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movfun</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>During calculations the data input <var>x</var> is reshaped into a 2-dimensional <var>wlen</var>-by-<var>N</var> matrix and <var>fcn</var> is called on this new matrix. Therefore, <var>fcn</var> must accept an array input argument and apply the computation along dimension 1, i.e., down the columns of the array. </p> <p>When applied to an array (possibly multi-dimensional) with <var>n</var> columns, <var>fcn</var> may return a result in either of two formats: Format 1)<!-- /@w --> an array of size 1-by-<var>n</var>-by-<var>dim3</var>-by-…-by-<var>dimN</var>. This is the typical output format from Octave core functions. Type <code>demo ("movfun", 5)</code> for an example of this use case. Format 2)<!-- /@w --> a row vector of length <code><var>n</var> * <var>numel_higher_dims</var></code> where <var>numel_higher_dims</var> is <code>prod (size (<var>x</var>)(3:end))</code><!-- /@w -->. The output of <var>fcn</var> for the i-th input column must be found in the output at indices <code>i:<var>n</var>:(<var>n</var>*<var><span class="nolinebreak">numel_higher_dims</span></var>)</code><!-- /@w -->. This format is useful when concatenating functions into arrays, or when using <code>nthargout</code>. Type <code>demo ("movfun", 6)</code> for an example of this case. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"dim"</code></dt> <dd><p>Operate along the dimension specified, rather than the default of the first non-singleton dimension. </p> </dd> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = <var>fcn</var> (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = <var>fcn</var> (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = <var>fcn</var> ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = <var>fcn</var> ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <var>fcn</var> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = <var>fcn</var> ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = <var>fcn</var> ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = <var>fcn</var> ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = <var>fcn</var> ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = <var>fcn</var> ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = <var>fcn</var> ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> <p>Note that for some of these choices, the window size at the boundaries is not the same as for the central part, and <var>fcn</var> must work in these cases. </p> </dd> <dt><code>"nancond"</code></dt> <dd><p>Controls whether <code>NaN</code> and <code>NA</code> values should be included (value: <code>"includenan"</code>), or excluded (value: <code>"omitnan"</code>), from the data passed to <var>fcn</var>. The default is <code>"includenan"</code>. Caution: The <code>"omitnan"</code> option is not yet implemented. </p> </dd> <dt><code>"outdim"</code></dt> <dd><p>A row vector that selects which dimensions of the calculation will appear in the output <var>y</var>. This is only useful when <var>fcn</var> returns an N-dimensional array in Format 1<!-- /@w -->. The default is to return all output dimensions. </p> </dd> </dl> <p>Programming Note: The property <code>"outdim"</code> can be used to save memory when the output of <var>fcn</var> has many dimensions, or when a wrapper to the base function that selects the desired outputs is too costly. When memory is not an issue, the easiest way to select output dimensions is to first calculate the complete result with <code>movfun</code> and then filter that result with indexing. If code complexity is not an issue then a wrapper can be created using anonymous functions. For example, if <code>basefcn</code> is a function returning a <var>K</var>-dimensional row output, and only dimension <var>D</var> is desired, then the following wrapper could be used. </p> <div class="example"> <pre class="example"><var>fcn</var> = @(x) basefcn (x)(:,size(x,2) * (<var>D</var>-1) + (1:size(x,2))); <var>y</var> = movfun (@fcn, …); </pre></div> <p><strong>See also:</strong> <a href="#XREFmovslice">movslice</a>, <a href="Rearranging-Matrices.html#XREFprepad">prepad</a>, <a href="Rearranging-Matrices.html#XREFpostpad">postpad</a>, <a href="Rearranging-Matrices.html#XREFpermute">permute</a>, <a href="Rearranging-Matrices.html#XREFreshape">reshape</a>. </p></dd></dl> <a name="XREFmovslice"></a><dl> <dt><a name="index-movslice"></a><em><var>slcidx</var> =</em> <strong>movslice</strong> <em>(<var>N</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movslice-1"></a><em>[<var>slcidx</var>, <var>C</var>, <var>Cpre</var>, <var>Cpost</var>, <var>win</var>] =</em> <strong>movslice</strong> <em>(…)</em></dt> <dd><p>Generate indices to slice a vector of length <var>N</var> in to windows of length <var>wlen</var>. </p> <p>FIXME: Document inputs N, wlen </p> <p>FIXME: Document outputs slcidx, C, Cpre, Cpost, win. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>. </p></dd></dl> <a name="XREFmovmad"></a><dl> <dt><a name="index-movmad"></a><em><var>y</var> =</em> <strong>movmad</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movmad-1"></a><em><var>y</var> =</em> <strong>movmad</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movmad-2"></a><em><var>y</var> =</em> <strong>movmad</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movmad-3"></a><em><var>y</var> =</em> <strong>movmad</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movmad-4"></a><em><var>y</var> =</em> <strong>movmad</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving mean absolute deviation over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>mad</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movmad</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movmad</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>mad</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = mad (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = mad (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = mad ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mad ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>mad</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = mad ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mad ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = mad ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mad ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = mad ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mad ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovmax"></a><dl> <dt><a name="index-movmax"></a><em><var>y</var> =</em> <strong>movmax</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movmax-1"></a><em><var>y</var> =</em> <strong>movmax</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movmax-2"></a><em><var>y</var> =</em> <strong>movmax</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movmax-3"></a><em><var>y</var> =</em> <strong>movmax</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movmax-4"></a><em><var>y</var> =</em> <strong>movmax</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving maximum over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>max</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movmax</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movmax</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>max</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = max (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = max (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = max ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = max ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>max</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = max ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = max ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = max ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = max ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = max ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = max ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovmean"></a><dl> <dt><a name="index-movmean"></a><em><var>y</var> =</em> <strong>movmean</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movmean-1"></a><em><var>y</var> =</em> <strong>movmean</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movmean-2"></a><em><var>y</var> =</em> <strong>movmean</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movmean-3"></a><em><var>y</var> =</em> <strong>movmean</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movmean-4"></a><em><var>y</var> =</em> <strong>movmean</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving average over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>mean</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movmean</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movmean</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>mean</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = mean (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = mean (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = mean ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mean ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>mean</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = mean ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mean ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = mean ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mean ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = mean ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = mean ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovmedian"></a><dl> <dt><a name="index-movmedian"></a><em><var>y</var> =</em> <strong>movmedian</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movmedian-1"></a><em><var>y</var> =</em> <strong>movmedian</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movmedian-2"></a><em><var>y</var> =</em> <strong>movmedian</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movmedian-3"></a><em><var>y</var> =</em> <strong>movmedian</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movmedian-4"></a><em><var>y</var> =</em> <strong>movmedian</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving median over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>movmedian</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movmedian</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movmedian</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>movmedian</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = movmedian (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = movmedian (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = movmedian ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movmedian ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>movmedian</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = movmedian ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movmedian ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = movmedian ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movmedian ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = movmedian ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movmedian ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovmin"></a><dl> <dt><a name="index-movmin"></a><em><var>y</var> =</em> <strong>movmin</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movmin-1"></a><em><var>y</var> =</em> <strong>movmin</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movmin-2"></a><em><var>y</var> =</em> <strong>movmin</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movmin-3"></a><em><var>y</var> =</em> <strong>movmin</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movmin-4"></a><em><var>y</var> =</em> <strong>movmin</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving minimum over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>min</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movmin</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movmin</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>min</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = min (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = min (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = min ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = min ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>min</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = min ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = min ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = min ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = min ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = min ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = min ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovprod"></a><dl> <dt><a name="index-movprod"></a><em><var>y</var> =</em> <strong>movprod</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movprod-1"></a><em><var>y</var> =</em> <strong>movprod</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movprod-2"></a><em><var>y</var> =</em> <strong>movprod</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movprod-3"></a><em><var>y</var> =</em> <strong>movprod</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movprod-4"></a><em><var>y</var> =</em> <strong>movprod</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving product over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>movprod</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movprod</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movprod</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>movprod</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = movprod (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = movprod (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = movprod ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movprod ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>movprod</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = movprod ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movprod ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = movprod ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movprod ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = movprod ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movprod ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovstd"></a><dl> <dt><a name="index-movstd"></a><em><var>y</var> =</em> <strong>movstd</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movstd-1"></a><em><var>y</var> =</em> <strong>movstd</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movstd-2"></a><em><var>y</var> =</em> <strong>movstd</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movstd-3"></a><em><var>y</var> =</em> <strong>movstd</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movstd-4"></a><em><var>y</var> =</em> <strong>movstd</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving standard deviation over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>movstd</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movstd</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movstd</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>movstd</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = movstd (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = movstd (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = movstd ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movstd ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>movstd</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = movstd ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movstd ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = movstd ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movstd ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = movstd ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movstd ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovsum">movsum</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovsum"></a><dl> <dt><a name="index-movsum"></a><em><var>y</var> =</em> <strong>movsum</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movsum-1"></a><em><var>y</var> =</em> <strong>movsum</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movsum-2"></a><em><var>y</var> =</em> <strong>movsum</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movsum-3"></a><em><var>y</var> =</em> <strong>movsum</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movsum-4"></a><em><var>y</var> =</em> <strong>movsum</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving sum over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>movsum</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movsum</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movsum</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>movsum</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = movsum (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = movsum (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = movsum ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movsum ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>movsum</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = movsum ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movsum ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = movsum ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movsum ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = movsum ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = movsum ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovvar">movvar</a>. </p></dd></dl> <a name="XREFmovvar"></a><dl> <dt><a name="index-movvar"></a><em><var>y</var> =</em> <strong>movvar</strong> <em>(<var>x</var>, <var>wlen</var>)</em></dt> <dt><a name="index-movvar-1"></a><em><var>y</var> =</em> <strong>movvar</strong> <em>(<var>x</var>, [<var>na</var>, <var>nb</var>])</em></dt> <dt><a name="index-movvar-2"></a><em><var>y</var> =</em> <strong>movvar</strong> <em>(…, <var>dim</var>)</em></dt> <dt><a name="index-movvar-3"></a><em><var>y</var> =</em> <strong>movvar</strong> <em>(…, "<var>nancond</var>")</em></dt> <dt><a name="index-movvar-4"></a><em><var>y</var> =</em> <strong>movvar</strong> <em>(…, <var>property</var>, <var>value</var>)</em></dt> <dd><p>Calculate the moving variance over a sliding window of length <var>wlen</var> on data <var>x</var>. </p> <p>If <var>wlen</var> is a scalar, the function <code>var</code> is applied to a moving window of length <var>wlen</var>. When <var>wlen</var> is an odd number the window is symmetric and includes <code>(<var>wlen</var> <span class="nolinebreak">-</span> 1) / 2</code><!-- /@w --> elements on either side of the central element. For example, when calculating the output at index 5 with a window length of 3, <code>movvar</code> uses data elements <code>[4, 5, 6]</code><!-- /@w -->. If <var>wlen</var> is an even number, the window is asymmetric and has <code><var>wlen</var>/2</code><!-- /@w --> elements to the left of the central element and <code><var>wlen</var>/2 <span class="nolinebreak">-</span> 1</code><!-- /@w --> elements to the right of the central element. For example, when calculating the output at index 5 with a window length of 4, <code>movvar</code> uses data elements <code>[3, 4, 5, 6]</code><!-- /@w -->. </p> <p>If <var>wlen</var> is an array with two elements <code>[<var>nb</var>, <var>na</var>]</code><!-- /@w -->, the function is applied to a moving window <code>-<var>nb</var>:<var>na</var></code>. This window includes <var>nb</var> number of elements <em>before</em> the current element and <var>na</var> number of elements <em>after</em> the current element. The current element is always included. For example, given <code><var>wlen</var> = [3, 0]</code><!-- /@w -->, the data used to calculate index 5 is <code>[2, 3, 4, 5]</code><!-- /@w -->. </p> <p>If the optional argument <var>dim</var> is given, operate along this dimension. </p> <p>The optional string argument <code>"<var>nancond</var>"</code> controls whether <code>NaN</code> and <code>NA</code> values should be included (<code>"includenan"</code>), or excluded (<code>"omitnan"</code>), from the data passed to <code>var</code>. The default is <code>"includenan"</code>. Caution: the <code>"omitnan"</code> option is not yet implemented. </p> <p>The calculation can be controlled by specifying <var>property</var>/<var>value</var> pairs. Valid properties are </p> <dl compact="compact"> <dt><code>"Endpoints"</code></dt> <dd> <p>This property controls how results are calculated at the boundaries (endpoints<!-- /@w -->) of the window. Possible values are: </p> <dl compact="compact"> <dt><code>"shrink"</code> (default)</dt> <dd><p>The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, <code><var>y</var>(1) = var (<var>x</var>(1:2))</code>, and <code><var>y</var>(end) = var (<var>x</var>(end-1:end))</code>. </p> </dd> <dt><code>"discard"</code></dt> <dd><p>Any <var>y</var> values that use a window extending beyond the original data array are deleted. For example, with a 10-element data vector and a window of length 3, the output will contain only 8 elements. The first element would require calculating the function over indices <code>[0, 1, 2]</code><!-- /@w --> and is therefore discarded. The last element would require calculating the function over indices <code>[9, 10, 11]</code><!-- /@w --> and is therefore discarded. </p> </dd> <dt><code>"fill"</code></dt> <dd><p>Any window elements outside the data array are replaced by <code>NaN</code>. For example, with a window of length 3, <code><var>y</var>(1) = var ([NaN, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = var ([<var>x</var>(end-1:end), NaN])</code>. This option usually results in <var>y</var> having <code>NaN</code> values at the boundaries, although it is influenced by how <code>var</code> handles <code>NaN</code>, and also by the property <code>"nancond"</code>. </p> </dd> <dt><var>user_value</var></dt> <dd><p>Any window elements outside the data array are replaced by the specified value <var>user_value</var> which must be a numeric scalar. For example, with a window of length 3, <code><var>y</var>(1) = var ([<var>user_value</var>, <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = var ([<var>x</var>(end-1:end), <var>user_value</var>])</code>. A common choice for <var>user_value</var> is 0. </p> </dd> <dt><code>"same"</code></dt> <dd><p>Any window elements outside the data array are replaced by the value of <var>x</var> at the boundary. For example, with a window of length 3, <code><var>y</var>(1) = var ([<var>x</var>(1), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = var ([<var>x</var>(end-1:end), <var>x</var>(end)])</code>. </p> </dd> <dt><code>"periodic"</code></dt> <dd><p>The window is wrapped so that any missing data elements are taken from the other side of the data. For example, with a window of length 3, <code><var>y</var>(1) = var ([<var>x</var>(end), <var>x</var>(1:2)])</code>, and <code><var>y</var>(end) = var ([<var>x</var>(end-1:end), <var>x</var>(1)])</code>. </p> </dd> </dl> </dd> <dt><code>"SamplePoints"</code></dt> <dd><p>Caution: This option is not yet implemented. </p> </dd> </dl> <p>Programming Note: This function is a wrapper which calls <code>movfun</code>. For additional options and documentation, See <a href="#XREFmovfun">movfun</a>. </p> <p><strong>See also:</strong> <a href="#XREFmovfun">movfun</a>, <a href="#XREFmovslice">movslice</a>, <a href="#XREFmovmad">movmad</a>, <a href="#XREFmovmax">movmax</a>, <a href="#XREFmovmean">movmean</a>, <a href="#XREFmovmedian">movmedian</a>, <a href="#XREFmovmin">movmin</a>, <a href="#XREFmovprod">movprod</a>, <a href="#XREFmovstd">movstd</a>, <a href="#XREFmovsum">movsum</a>. </p></dd></dl> <hr> <div class="header"> <p> Next: <a href="Basic-Statistical-Functions.html#Basic-Statistical-Functions" accesskey="n" rel="next">Basic Statistical Functions</a>, Previous: <a href="Descriptive-Statistics.html#Descriptive-Statistics" accesskey="p" rel="prev">Descriptive Statistics</a>, Up: <a href="Statistics.html#Statistics" accesskey="u" rel="up">Statistics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> </body> </html>