annotate scripts/signal/movfun.m @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents eb1903f8bf98
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26261
diff changeset
1 ## Copyright (C) 2018-2019 Juan Pablo Carbajal
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
2 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
3 ## This file is part of Octave.
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
4 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
6 ## under the terms of the GNU General Public License as published by
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
8 ## (at your option) any later version.
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
9 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
13 ## GNU General Public License for more details.
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
14 ##
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
17 ## <https://www.gnu.org/licenses/>.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
18
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
19 ## Author: Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
20 ## Created: 2018-08-09
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
21
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
22 ## -*- texinfo -*-
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
23 ## @deftypefn {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{wlen})
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
24 ## @deftypefnx {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{[@var{nb}, @var{na}}])
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
25 ## @deftypefnx {} {@var{y} =} movfun (@dots{}, "@var{property}", @var{value})
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
26 ##
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
27 ## Apply function @var{fcn} to a moving window of length @var{wlen} on data
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
28 ## @var{x}.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
29 ##
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
30 ## If @var{wlen} is a scalar, the function @var{fcn} is applied to a moving
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
31 ## window of length @var{wlen}. When @var{wlen} is an odd number the window is
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
32 ## symmetric and includes @w{@code{(@var{wlen} - 1) / 2}} elements on either
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
33 ## side of the central element. For example, when calculating the output at
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
34 ## index 5 with a window length of 3, @code{movfun} uses data elements
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
35 ## @w{@code{[4, 5, 6]}}. If @var{wlen} is an even number, the window is
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
36 ## asymmetric and has @w{@code{@var{wlen}/2}} elements to the left of the
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
37 ## central element and @w{@code{@var{wlen}/2 - 1}} elements to the right of the
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
38 ## central element. For example, when calculating the output at index 5 with a
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
39 ## window length of 4, @code{movfun} uses data elements
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
40 ## @w{@code{[3, 4, 5, 6]}}.
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
41 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
42 ## If @var{wlen} is an array with two elements @w{@code{[@var{nb}, @var{na}]}},
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
43 ## the function is applied to a moving window @code{-@var{nb}:@var{na}}. This
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
44 ## window includes @var{nb} number of elements @emph{before} the current
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
45 ## element and @var{na} number of elements @emph{after} the current element.
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
46 ## The current element is always included. For example, given
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
47 ## @w{@code{@var{wlen} = [3, 0]}}, the data used to calculate index 5 is
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
48 ## @w{@code{[2, 3, 4, 5]}}.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
49 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
50 ## During calculations the data input @var{x} is reshaped into a 2-dimensional
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
51 ## @var{wlen}-by-@var{N} matrix and @var{fcn} is called on this new matrix.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
52 ## Therefore, @var{fcn} must accept an array input argument and apply the
26255
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
53 ## computation along dimension 1, i.e., down the columns of the array.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
54 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
55 ## When applied to an array (possibly multi-dimensional) with @var{n} columns,
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
56 ## @var{fcn} may return a result in either of two formats: @w{Format 1)}
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
57 ## an array of size 1-by-@var{n}-by-@var{dim3}-by-@dots{}-by-@var{dimN}. This
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
58 ## is the typical output format from Octave core functions. Type
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
59 ## @code{demo ("movfun", 5)} for an example of this use case.
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
60 ## @w{Format 2)} a row vector of length
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
61 ## @code{@var{n} * @var{numel_higher_dims}} where @var{numel_higher_dims} is
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
62 ## @w{@code{prod (size (@var{x})(3:end))}}. The output of @var{fcn} for the
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
63 ## i-th input column must be found in the output at indices
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
64 ## @w{@code{i:@var{n}:(@var{n}*@var{numel_higher_dims})}}.
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
65 ## This format is useful when concatenating functions into arrays, or when
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
66 ## using @code{nthargout}. Type @code{demo ("movfun", 6)} for an example of
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
67 ## this case.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
68 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
69 ## The calculation can be controlled by specifying @var{property}/@var{value}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
70 ## pairs. Valid properties are
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
71 ##
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
72 ## @table @asis
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
73 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
74 ## @item @qcode{"dim"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
75 ## Operate along the dimension specified, rather than the default of the first
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
76 ## non-singleton dimension.
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
77 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
78 ## @item @qcode{"Endpoints"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
79 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
80 ## This property controls how results are calculated at the boundaries
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
81 ## (@w{endpoints}) of the window. Possible values are:
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
82 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
83 ## @table @asis
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
84 ## @item @qcode{"shrink"} (default)
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
85 ## The window is truncated at the beginning and end of the array to exclude
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
86 ## elements for which there is no source data. For example, with a window of
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
87 ## length 3, @code{@var{y}(1) = @var{fcn} (@var{x}(1:2))}, and
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
88 ## @code{@var{y}(end) = @var{fcn} (@var{x}(end-1:end))}.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
89 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
90 ## @item @qcode{"discard"}
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
91 ## Any @var{y} values that use a window extending beyond the original
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
92 ## data array are deleted. For example, with a 10-element data vector and a
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
93 ## window of length 3, the output will contain only 8 elements. The first
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
94 ## element would require calculating the function over indices
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
95 ## @w{@code{[0, 1, 2]}} and is therefore discarded. The last element would
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
96 ## require calculating the function over indices @w{@code{[9, 10, 11]}} and is
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
97 ## therefore discarded.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
98 ##
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
99 ## @item @qcode{"fill"}
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
100 ## Any window elements outside the data array are replaced by @code{NaN}. For
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
101 ## example, with a window of length 3,
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
102 ## @code{@var{y}(1) = @var{fcn} ([NaN, @var{x}(1:2)])}, and
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
103 ## @code{@var{y}(end) = @var{fcn} ([@var{x}(end-1:end), NaN])}.
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
104 ## This option usually results in @var{y} having @code{NaN} values at the
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
105 ## boundaries, although it is influenced by how @var{fcn} handles @code{NaN},
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
106 ## and also by the property @qcode{"nancond"}.
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
107 ##
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
108 ## @item @var{user_value}
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
109 ## Any window elements outside the data array are replaced by the specified
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
110 ## value @var{user_value} which must be a numeric scalar. For example, with a
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
111 ## window of length 3,
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
112 ## @code{@var{y}(1) = @var{fcn} ([@var{user_value}, @var{x}(1:2)])}, and
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
113 ## @code{@var{y}(end) = @var{fcn} ([@var{x}(end-1:end), @var{user_value}])}.
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
114 ## A common choice for @var{user_value} is 0.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
115 ##
26255
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
116 ## @item @qcode{"same"}
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
117 ## Any window elements outside the data array are replaced by the value of
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
118 ## @var{x} at the boundary. For example, with a window of length 3,
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
119 ## @code{@var{y}(1) = @var{fcn} ([@var{x}(1), @var{x}(1:2)])}, and
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
120 ## @code{@var{y}(end) = @var{fcn} ([@var{x}(end-1:end), @var{x}(end)])}.
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
121 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
122 ## @item @qcode{"periodic"}
26255
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
123 ## The window is wrapped so that any missing data elements are taken from
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
124 ## the other side of the data. For example, with a window of length 3,
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
125 ## @code{@var{y}(1) = @var{fcn} ([@var{x}(end), @var{x}(1:2)])}, and
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
126 ## @code{@var{y}(end) = @var{fcn} ([@var{x}(end-1:end), @var{x}(1)])}.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
127 ##
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
128 ## @end table
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
129 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
130 ## Note that for some of these choices, the window size at the boundaries is
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
131 ## not the same as for the central part, and @var{fcn} must work in these
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
132 ## cases.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
133 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
134 ## @item @qcode{"nancond"}
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
135 ## Controls whether @code{NaN} and @code{NA} values should be included (value:
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
136 ## @qcode{"includenan"}), or excluded (value: @qcode{"omitnan"}), from the data
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
137 ## passed to @var{fcn}. The default is @qcode{"includenan"}. Caution:
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
138 ## The @qcode{"omitnan"} option is not yet implemented.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
139 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
140 ## @item @qcode{"outdim"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
141 ## A row vector that selects which dimensions of the calculation will appear
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
142 ## in the output @var{y}. This is only useful when @var{fcn} returns an
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
143 ## N-dimensional array in @w{Format 1}. The default is to return all output
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
144 ## dimensions.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
145 ##
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
146 ## @end table
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
147 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
148 ## Programming Note: The property @qcode{"outdim"} can be used to save memory
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
149 ## when the output of @var{fcn} has many dimensions, or when a wrapper to the
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
150 ## base function that selects the desired outputs is too costly. When memory
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
151 ## is not an issue, the easiest way to select output dimensions is to first
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
152 ## calculate the complete result with @code{movfun} and then filter that result
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
153 ## with indexing. If code complexity is not an issue then a wrapper can be
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
154 ## created using anonymous functions. For example, if @code{basefcn}
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
155 ## is a function returning a @var{K}-dimensional row output, and only
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
156 ## dimension @var{D} is desired, then the following wrapper could be used.
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
157 ##
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
158 ## @example
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
159 ## @group
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
160 ## @var{fcn} = @@(x) basefcn (x)(:,size(x,2) * (@var{D}-1) + (1:size(x,2)));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
161 ## @var{y} = movfun (@@fcn, @dots{});
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
162 ## @end group
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
163 ## @end example
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
164 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
165 ## @seealso{movslice, prepad, postpad, permute, reshape}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
166 ## @end deftypefn
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
167
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
168 function y = movfun (fcn, x, wlen, varargin)
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
169
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
170 if (nargin < 3)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
171 print_usage ();
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
172 endif
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
173
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
174 valid_bc = {"shrink", "discard", "fill", "same", "periodic"};
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
175
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
176 ## Parse input arguments
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
177 parser = inputParser ();
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
178 parser.FunctionName = "movfun";
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
179 parser.addParamValue ("Endpoints", "shrink", ...
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
180 @(x) any (strcmpi (x, valid_bc)) || (isnumeric (x) && isscalar (x)));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
181 parser.addParamValue ("dim", [], ...
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
182 @(d) isempty (d) || (isscalar (d) && isindex (d, ndims (x))));
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
183 parser.addParamValue ("nancond", "includenan", ...
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
184 @(x) any (strcmpi (x, {"includenan", "omitnan"})));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
185 parser.addParamValue ("outdim", [], ...
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
186 @(d) isempty (d) || (isvector (d) && isindex (d)));
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
187
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
188 parser.parse (varargin{:});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
189 bc = parser.Results.Endpoints; # boundary condition
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
190 dim = parser.Results.dim; # dimension to be used as input
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
191 nancond = parser.Results.nancond; # whether NaN are ignored or not
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
192 outdim = parser.Results.outdim; # selected output dimension of fcn
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
193 clear parser
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
194 ## End parse input arguments
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
195
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
196 ## If dim was not provided find the first non-singleton dimension.
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
197 szx = size (x);
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
198 if (isempty (dim))
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
199 (dim = find (szx > 1, 1)) || (dim = 1);
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
200 endif
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
201
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
202 N = szx(dim);
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
203
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
204 ## Calculate slicing indices. This call also validates WLEN input.
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
205 [slc, C, Cpre, Cpos, win] = movslice (N, wlen);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
206
26259
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
207 ## Use [nb, na] format which makes replaceval_bc() simpler.
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
208 if (isscalar (wlen))
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
209 wlen = [wlen, wlen];
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
210 endif
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
211
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
212 omitnan = strcmpi (nancond, "omitnan");
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
213 if (omitnan)
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
214 warning ('movfun: "omitnan" is not yet implemented, using "includenan"');
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
215 endif
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
216
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
217 ## Move the desired dim to be the 1st dimension (rows)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
218 nd = length (szx); # number of dimensions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
219 dperm = [dim, 1:(dim-1), (dim+1):nd]; # permutation of dimensions
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
220 x = permute (x, dperm); # permute dims to first dimension
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
221 ncols = prod (szx(dperm(2:end))); # rest of dimensions as single column
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
222 x = reshape (x, N, ncols); # reshape input
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
223
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
224 ## Obtain function for boundary conditions
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
225 if (isnumeric (bc))
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
226 bcfunc = @replaceval_bc;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
227 bcfunc (true, bc); # initialize replaceval function with value
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
228 else
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
229 switch (tolower (bc))
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
230 case "shrink"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
231 bcfunc = @shrink_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
232
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
233 case "discard"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
234 bcfunc = [];
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
235 C -= length (Cpre);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
236 Cpre = Cpos = [];
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
237 N = length (C);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
238 szx(dperm(1)) = N;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
239
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
240 case "fill"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
241 bcfunc = @replaceval_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
242 bcfunc (true, NaN);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
243
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
244 case "same"
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
245 bcfunc = @same_bc;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
246
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
247 case "periodic"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
248 bcfunc = @periodic_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
249
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
250 endswitch
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
251 endif
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
252
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
253 ## FIXME: Validation doesn't seem to work correctly (noted 12/16/2018).
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
254 ## Validate that outdim makes sense
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
255 tmp = fcn (zeros (length (win), 1)); # output for window
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
256 noutdim = length (tmp); # number of output dimensions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
257 if (! isempty (outdim))
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
258 if (max (outdim) > noutdim)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
259 error ("Octave:invalid-input-arg", ...
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
260 "movfun: output dimension OUTDIM (%d) is larger than largest available dimension (%d)", ...
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
261 max (outdim), noutdim);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
262 endif
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
263 else
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
264 outdim = 1:noutdim;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
265 endif
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
266 soutdim = length (outdim); # length of selected output dimensions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
267 ## If noutdim is not one then modify function to handle multiple outputs
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
268 if (noutdim > 1)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
269 fcn_ = @(x) reshape (fcn (x), columns (x), noutdim)(:, outdim);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
270 else
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
271 fcn_ = fcn;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
272 endif
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
273
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
274 ## Apply processing to each column
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
275 ## FIXME: Is it faster with cellfun? Don't think so, but needs testing.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
276 y = zeros (N, ncols, soutdim);
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
277 parfor i = 1:ncols
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
278 y(:,i,:) = movfun_oncol (fcn_, x(:,i), wlen, bcfunc,
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
279 slc, C, Cpre, Cpos, win, soutdim);
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
280 endparfor
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
281
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
282 ## Restore shape
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
283 y = reshape (y, [szx(dperm), soutdim]);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
284 y = permute (y, [dperm, nd+1]);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
285 y = squeeze (y);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
286
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
287 endfunction
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
288
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
289 function y = movfun_oncol (fcn, x, wlen, bcfunc, slcidx, C, Cpre, Cpos, win, odim)
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
290
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
291 N = length (Cpre) + length (C) + length (Cpos);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
292 y = NA (N, odim);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
293
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
294 ## Process center part
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
295 y(C,:) = fcn (x(slcidx));
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
296
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
297 ## Process boundaries
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
298 if (! isempty (Cpre))
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
299 y(Cpre,:) = bcfunc (fcn, x, Cpre, win, wlen, odim);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
300 endif
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
301 if (! isempty (Cpos))
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
302 y(Cpos,:) = bcfunc (fcn, x, Cpos, win, wlen, odim);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
303 endif
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
304
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
305 endfunction
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
306
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
307 ## Apply "shrink" boundary conditions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
308 ## Function is not applied to any window elements outside the original data.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
309 function y = shrink_bc (fcn, x, idxp, win, wlen, odim)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
310 N = length (x);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
311 idx = idxp + win;
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
312 tf = (idx > 0) & (idx <= N); # idx inside boundaries
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
313
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
314 n = length (idxp);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
315 y = zeros (n, odim);
26260
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
316 ## FIXME: This nested for loop accounts for 70% of running time.
9d3c22f7fff1 movfun.m: Make Texinfo documentation prettier by marking some items as non-breakable.
Rik <rik@octave.org>
parents: 26259
diff changeset
317 ## Given that "shrink" is the default Endpoint value this
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
318 ## code needs to be reworked.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
319 for i = 1:n
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
320 k = idx(tf(:,i),i);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
321 y(i,:) = fcn (x(k));
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
322 endfor
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
323 endfunction
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
324
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
325 ## Apply replacement value boundary conditions
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
326 ## Window is padded at beginning and end with user-specified value.
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
327 function y = replaceval_bc (fcn, x, idxp, win, wlen)
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
328
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
329 persistent substitute;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
330
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
331 ## In-band method to initialize substitute value
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
332 if (islogical (fcn))
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
333 substitute = x;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
334 return;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
335 endif
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
336
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
337 if (min (idxp) == 1)
26259
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
338 ## pre-pad window
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
339 sz = size (x);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
340 sz(1) = wlen(1);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
341 x = [substitute(ones (sz)); x];
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
342 idx = idxp + win + wlen(1);
26259
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
343 else
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
344 ## post-pad window
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
345 sz = size (x);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
346 sz(1) = wlen(2);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
347 x = [x; substitute(ones (sz))];
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
348 idx = idxp + win;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
349 endif
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
350
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
351 y = fcn (x(idx));
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
352
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
353 endfunction
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
354
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
355 ## Apply "same" boundary conditions
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
356 ## 'y' values outside window are replaced by value of 'x' at the window
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
357 ## boundary.
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
358 function y = same_bc (fcn, x, idxp, win)
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
359 idx = idxp + win;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
360 idx(idx < 1) = 1;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
361 N = length (x);
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
362 idx(idx > N) = N;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
363 y = fcn (x(idx));
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
364 endfunction
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
365
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
366 ## Apply "periodic" boundary conditions
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
367 ## Window wraps around. Window values outside data array are replaced with
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
368 ## data from the other end of the array.
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
369 function y = periodic_bc (fcn, x, idxp, win)
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
370 N = length (x);
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
371 idx = idxp + win;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
372 tf = idx < 1;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
373 idx(tf) = N + idx(tf);
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
374 tf = idx > N;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
375 idx(tf) = idx(tf) - N;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
376 y = fcn (x(idx));
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
377 endfunction
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
378
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
379
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
380 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
381 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
382 %! t = 2 * pi * linspace (0,1,100).';
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
383 %! x = sin (3 * t);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
384 %! xn = x + 0.1 * randn (size (x));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
385 %! x_s = movfun (@mean, xn, 5, "Endpoints", "shrink");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
386 %! x_p = movfun (@mean, xn, 5, "Endpoints", "periodic");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
387 %! x_m = movfun (@mean, xn, 5, "Endpoints", "same");
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
388 %! x_z = movfun (@mean, xn, 5, "Endpoints", 0);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
389 %! x_f = movfun (@mean, xn, 5, "Endpoints", "fill");
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
390 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
391 %! h = plot (t, xn, "o;noisy signal;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
392 %! t, x, "-;true;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
393 %! t, x_s, "-;shrink;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
394 %! t, x_p, "-;periodic;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
395 %! t, x_m, "-;same;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
396 %! t, x_z, "-;zero;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
397 %! t, x_f, "-;fill;");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
398 %! set (h(1), "markerfacecolor", "auto");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
399 %! set (h(2:end), "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
400 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
401 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
402 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
403 %! title ("moving mean with different boundary conditions");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
404 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
405 %! # Moving mean of noisy sinusoidal function with different boundary
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
406 %! # conditions.
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
407
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
408 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
409 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
410 %! t = 2 * pi * linspace (0,1,100).';
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
411 %! x = sin (3 * t);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
412 %! xn = x + 0.1 * randn (size (x));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
413 %! nwin = 5;
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
414 %! x_ = zeros (rows (x), nwin);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
415 %! wlen = 3 + (1:nwin) * 4;
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
416 %! for i = 1:nwin
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
417 %! x_(:,i) = movfun (@mean, xn, wlen(i), "Endpoints", "periodic");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
418 %! endfor
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
419 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
420 %! h = plot (t, xn, "o",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
421 %! t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
422 %! t, x_, "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
423 %! set (h(1), "markerfacecolor", "auto");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
424 %! set (h(2:end), "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
425 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
426 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
427 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
428 %! title ({'moving mean with "periodic" boundary conditions',
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
429 %! "and windows of different lengths"});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
430 %! legend (h, {"noisy", "true", strsplit(num2str(wlen)){:}});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
431 %! #-----------------------------------------------------------------
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
432 %! # Moving mean of noisy sinusoidal function with periodic boundary conditions
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
433 %! # using windows of different lengths.
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
434
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
435 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
436 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
437 %! t = linspace (0,1,100).';
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
438 %! x = exp (-(t - [0.1:0.3:1]).^2/2/0.1^2);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
439 %! y = movfun (@max, x, 15);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
440 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
441 %! h = plot (t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
442 %! t, y, "--");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
443 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
444 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
445 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
446 %! title ("moving max of several Gaussian functions");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
447 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
448 %! # Moving max of different Gaussian functions.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
449 %! # Illustrates the application of movfun() to inputs with several columns.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
450
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
451 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
452 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
453 %! t = linspace (0,1-1e-2,100).';
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
454 %! w = 2 * pi * 3;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
455 %! x = sin (w * t);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
456 %! y = cos (w * t);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
457 %! y_ = movfun (@diff, x, [1 0], "Endpoints", "periodic");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
458 %! ## Is the same as y_ = x(2:end) - x(1:end-1);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
459 %! dt = t(2) - t(1);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
460 %! y_ = y_ / w / dt;
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
461 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
462 %! h = plot (t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
463 %! t, y, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
464 %! t, y_, ":");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
465 %! set (h, "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
466 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
467 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
468 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
469 %! title ("movfun with periodic boundary conditions and asymmetric window");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
470 %! legend (h, {"sin", "cos", "[nb, na]"});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
471 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
472 %! # Backward diff() of sinusoidal function with periodic boundary conditions.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
473 %! # Illustrates the use of asymmetric windows.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
474
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
475 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
476 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
477 %! N = 1e3;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
478 %! wlen = 99;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
479 %! x = linspace (-1, 1, N).';
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
480 %! pp = [-2 0 1 0];
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
481 %! y = polyval (pp, x);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
482 %! yn = y + 0.1 * (abs (y) + 0.5) .* exp (randn (N, 1));
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
483 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
484 %! st = movfun (@(y) (statistics (y)).', yn, wlen);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
485 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
486 %! h = plot (x, y, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
487 %! x, yn, ".",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
488 %! x, st(:,[3 6]), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
489 %! x, st(:,6) + [-1 1].*st(:,7), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
490 %! x, st(:,[1 2 4 5]), "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
491 %! set (h([1 3:4]), "linewidth", 3); # mean
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
492 %! set (h(5:end), "color", "k");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
493 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
494 %! xlabel ("x")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
495 %! ylabel ("y")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
496 %! title ("movfun() with Format 1 output data");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
497 %! legend (h, {"noiseless", "noisy", "mean", "median"})
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
498 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
499 %! # Moving window statistics. The plot highlights mean and median.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
500 %! # Black lines how minimum, first quartile, third quartile, and maximum.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
501 %! # Demo illustrates the use of functions with multidimensional output.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
502
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
503 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
504 %! clf;
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
505 %! N = 1e2;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
506 %! wlen = 9;
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
507 %! x = linspace (-1, 1, N).';
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
508 %! pp = [-2 0 1 0];
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
509 %! y = polyval (pp, x);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
510 %! y(:,2) = y + 0.1 * (abs (y) + 0.5) .* exp (randn (N, 1));
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
511 %! y(:,1) = -y(:,1) + 0.1 * randn (N, 1);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
512 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
513 %! fcn = @(y) [min(y), max(y)];
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
514 %! st = movfun (fcn, y, wlen);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
515 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
516 %! h = plot (x, y, "o",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
517 %! x, squeeze (st(:,1,:)), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
518 %! x, squeeze (st(:,2,:)), "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
519 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
520 %! set (h(3:4), "color", get (h(1), "color"));
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
521 %! set (h(5:6), "color", get (h(2), "color"));
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
522 %! xlabel ("x")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
523 %! ylabel ("y")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
524 %! title ("movfun() with Format 2 output data");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
525 %! legend (h(1:2), {"data1", "data2"})
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
526 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
527 %! # Moving min() and max() on the same window.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
528 %! # Demo illustrates the use of functions with flat multidimensional output.
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
529
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
530 %!test
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
531 %! x = (1:10).' + [-3, 0, 4];
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
532 %! ctrfun = @(x) x(2,:);
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
533 %! valid_bc = {"periodic", 0, "fill", "same"};
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
534 %! for bc = valid_bc
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
535 %! assert (movfun (ctrfun, x, 3, "Endpoints", bc{1}), x);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
536 %! endfor
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
537 %! x_ = x; x_([1 end],:) = x([2 end],:);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
538 %! assert (movfun (ctrfun, x, 3, "Endpoints", "shrink"), x_);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
539
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
540 %!test
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
541 %! ## dim == 2, same as transpose
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
542 %! x = randi (10, 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
543 %! ctrfun = @(x) x(2,:);
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
544 %! valid_bc = {"periodic", 0, "fill", "same"};
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
545 %! for bc = valid_bc
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
546 %! assert (movfun (ctrfun, x.', 3, "Endpoints", bc{1}, "dim", 2), x.');
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
547 %! endfor
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
548 %! x_ = x; x_([1 end],:) = x([2 end],:);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
549 %! assert (movfun (ctrfun, x.', 3, "Endpoints", "shrink", "dim", 2), x_.');
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
550
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
551 %!test
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
552 %! x = randi (10, 3, 10, 2);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
553 %! y = movfun (@(x) x(2,:), x, 3, "Endpoints", "same", "dim", 2);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
554 %! assert (x, y);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
555
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
556 %!test
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
557 %! ## bad zero_bc
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
558 %! x = ones (10, 1);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
559 %! y = x; y(1:2) = y([end end-1]) = [0.6;0.8];
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
560 %! assert (movfun (@mean, x, 5, "Endpoints", 0), y);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
561
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
562 ## Asymmetric windows
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
563 %!shared x, wlen, wlen02, wlen20, ctrfun, UNO
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
564 %! x = (1:10).' + [-3, 0, 4];
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
565 %! wlen = [2, 1];
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
566 %! wlen02 = [0, 2];
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
567 %! wlen20 = [2, 0];
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
568 %! ctrfun = @(x) x(wlen(1)+1,:);
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
569 %! UNO = ones (7,1);
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
570
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
571 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "periodic"), x)
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
572 %!assert (movfun (ctrfun, x, wlen, "Endpoints", 0), x)
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
573 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "fill"), x)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
574 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "same"), x)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
575 ## for shorter x, indexing fails
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
576 %!error movfun (ctrfun, x, wlen, "Endpoints", "shrink")
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
577
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
578 %!assert (movfun (@min, UNO, wlen, "Endpoints", "shrink"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
579 %!assert (movfun (@min, UNO, wlen02, "Endpoints", "shrink"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
580 %!assert (movfun (@min, UNO, wlen20, "Endpoints", "shrink"), UNO)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
581
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
582 %!assert (movfun (@min, UNO, wlen02, "Endpoints", "periodic"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
583 %!assert (movfun (@min, UNO, wlen20, "Endpoints", "periodic"), UNO)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
584
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
585 %!assert (movfun (@max, UNO, wlen02, "Endpoints", 0), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
586 %!assert (movfun (@max, UNO, wlen20, "Endpoints", 0), UNO)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
587
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
588 %!assert (movfun (@min, UNO, wlen02, "Endpoints", "fill"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
589 %!assert (movfun (@min, UNO, wlen20, "Endpoints", "fill"), UNO)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
590
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
591 %!assert (movfun (@min, UNO, wlen02, "Endpoints", "same"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
592 %!assert (movfun (@min, UNO, wlen20, "Endpoints", "same"), UNO)
26241
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
593
2d80a065ce9a Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff changeset
594 ## Multidimensional output
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
595 %!assert (size( movfun (@(x) [min(x), max(x)], (1:10).', 3)), [10 2])
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
596 %!assert (size( movfun (@(x) [min(x), max(x)], cumsum (ones (10,5),2), 3)),
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
597 %! [10 5 2])
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
598 ## outdim > dim
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
599 %!error (movfun (@(x) [min(x), max(x)], (1:10).', 3, "Outdim", 3))
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
600
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
601 ## Test input validation
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
602 %!error movfun ()
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
603 %!error movfun (@min)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
604 %!error movfun (@min, 1)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
605 %!error <WLEN must be .* array of integers> movfun (@min, 1, {1})
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
606 %!error <WLEN must be .* array of integers .= 0> movfun (@min, 1, -1)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
607 %!error <WLEN must be .* array of integers> movfun (@min, 1, 1.5)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
608 %!error <WLEN must be . 1> movfun (@min, 1, 1)
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
609 %!error <WLEN must be a scalar or 2-element array> movfun (@min, 1, [1, 2, 3])
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
610 %!error <WLEN \(3\) must be shorter than length along DIM \(1\)>
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
611 %! movfun (@min, 1, 3)
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
612 %!error <WLEN \(4\) must be shorter than length along DIM \(1\)>
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
613 %! movfun (@min, 1, [4, 1]);
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
614 %!error <WLEN \(5\) must be shorter than length along DIM \(1\)>
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
615 %! movfun (@min, 1, [1, 5]);
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
616 %!warning <"omitnan" is not yet implemented>
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
617 %! movfun (@min, 1:3, 3, "nancond", "omitnan");
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
618 ## FIXME: This test is commented out until OUTDIM validation is clarified.
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
619 %!#error <OUTDIM \(5\) is larger than largest available dimension \(3\)>
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
620 %! movfun (@min, ones (6,3,4), 3, "outdim", 5);