annotate scripts/signal/movfun.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 363fb10055df
children e1788b1a315f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30379
diff changeset
3 ## Copyright (C) 2018-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
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
7 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
8 ## 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
9 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
10 ## 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
11 ## 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
12 ## 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
13 ## (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
14 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
15 ## 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
16 ## 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
17 ## 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
18 ## 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
19 ##
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 ## 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
21 ## 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
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
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
25
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
26 ## -*- texinfo -*-
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
27 ## @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
28 ## @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
29 ## @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
30 ##
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
31 ## 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
32 ## @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
33 ##
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
34 ## 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
35 ## 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
36 ## 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
37 ## 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
38 ## 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
39 ## @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
40 ## 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
41 ## 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
42 ## 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
43 ## 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
44 ## @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
45 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
46 ## 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
47 ## 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
48 ## 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
49 ## 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
50 ## 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
51 ## @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
52 ## @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
53 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
54 ## 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
55 ## @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
56 ## 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
57 ## 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
58 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
59 ## 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
60 ## @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
61 ## 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
62 ## 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
63 ## @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
64 ## @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
65 ## @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
66 ## @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
67 ## 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
68 ## @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
69 ## 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
70 ## 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
71 ## 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
72 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
73 ## 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
74 ## 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
75 ##
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
76 ## @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
77 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
78 ## @item @qcode{"dim"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
79 ## 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
80 ## non-singleton dimension.
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
81 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
82 ## @item @qcode{"Endpoints"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
83 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
84 ## 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
85 ## (@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
86 ##
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
87 ## @table @asis
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
88 ## @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
89 ## 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
90 ## 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
91 ## 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
92 ## @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
93 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
94 ## @item @qcode{"discard"}
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
95 ## 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
96 ## 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
97 ## 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
98 ## 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
99 ## @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
100 ## 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
101 ## 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
102 ##
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
103 ## @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
104 ## 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
105 ## 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
106 ## @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
107 ## @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
108 ## 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
109 ## 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
110 ## 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
111 ##
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
112 ## @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
113 ## 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
114 ## 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
115 ## 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
116 ## @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
117 ## @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
118 ## 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
119 ##
26255
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
120 ## @item @qcode{"same"}
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
121 ## 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
122 ## @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
123 ## @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
124 ## @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
125 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
126 ## @item @qcode{"periodic"}
26255
36b96226107c movfun.m: Write more complete documentation for "same" option.
Rik <rik@octave.org>
parents: 26253
diff changeset
127 ## 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
128 ## 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
129 ## @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
130 ## @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
131 ##
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
132 ## @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
133 ##
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
134 ## 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
135 ## 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
136 ## 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
137 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
138 ## @item @qcode{"nancond"}
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
139 ## 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
140 ## @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
141 ## 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
142 ## 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
143 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
144 ## @item @qcode{"outdim"}
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
145 ## 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
146 ## 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
147 ## 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
148 ## 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
149 ##
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
150 ## @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
151 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
152 ## 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
153 ## 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
154 ## 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
155 ## 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
156 ## 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
157 ## 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
158 ## 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
159 ## 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
160 ## 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
161 ##
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
162 ## @example
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
163 ## @group
30236
628f26e122d9 maint: use rows() or columns() instead of size(__, 1 | 2) for clarity.
Rik <rik@octave.org>
parents: 29359
diff changeset
164 ## @var{fcn} = @@(x) basefcn (x)(:,columns(x) * (@var{D}-1) + (1:columns(x)));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
165 ## @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
166 ## @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
167 ## @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
168 ##
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
169 ## @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
170 ## @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
171
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
172 function y = movfun (fcn, x, wlen, varargin)
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
173
26248
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
174 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
175 print_usage ();
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
176 endif
8a0778f549e8 movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents: 26246
diff changeset
177
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
178 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
179
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
180 ## Parse input arguments
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
181 parser = inputParser ();
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
182 parser.FunctionName = "movfun";
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
183 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
184 @(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
185 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
186 @(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
187 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
188 @(x) any (strcmpi (x, {"includenan", "omitnan"})));
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
189 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
190 @(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
191
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
192 parser.parse (varargin{:});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
193 bc = parser.Results.Endpoints; # boundary condition
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
194 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
195 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
196 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
197 clear parser
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
198 ## 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
199
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
200 ## 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
201 szx = size (x);
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
202 if (isempty (dim))
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
203 (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
204 endif
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
205
26261
eb1903f8bf98 movfun.m: Tweak documentation and remove spaces at EOL.
Rik <rik@octave.org>
parents: 26260
diff changeset
206 N = szx(dim);
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
207
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
208 ## 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
209 [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
210
26259
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
211 ## 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
212 if (isscalar (wlen))
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
213 wlen = [wlen, wlen];
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
214 endif
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
215
26256
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
216 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
217 if (omitnan)
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
218 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
219 endif
d8ebeb1a82ea movfun.m: Change default nancond property value to "includenan" for Matlab compatibility.
Rik <rik@octave.org>
parents: 26255
diff changeset
220
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
221 ## 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
222 nd = length (szx); # number of dimensions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
223 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
224 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
225 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
226 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
227
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
228 ## 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
229 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
230 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
231 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
232 else
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
233 switch (tolower (bc))
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
234 case "shrink"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
235 bcfunc = @shrink_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
236
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
237 case "discard"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
238 bcfunc = [];
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
239 C -= length (Cpre);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
240 Cpre = Cpos = [];
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
241 N = length (C);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
242 szx(dperm(1)) = N;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
243
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
244 case "fill"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
245 bcfunc = @replaceval_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
246 bcfunc (true, NaN);
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
247
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
248 case "same"
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
249 bcfunc = @same_bc;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
250
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
251 case "periodic"
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
252 bcfunc = @periodic_bc;
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
253
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
254 endswitch
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
255 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
256
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
257 ## 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
258 ## Validate that outdim makes sense
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
259 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
260 noutdim = length (tmp); # number of output dimensions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
261 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
262 if (max (outdim) > noutdim)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
263 error ("Octave:invalid-input-arg", ...
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
264 "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
265 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
266 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
267 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
268 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
269 endif
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
270 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
271 ## 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
272 if (noutdim > 1)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
273 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
274 else
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
275 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
276 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
277
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
278 ## Apply processing to each column
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
279 ## 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
280 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
281 parfor i = 1:ncols
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
282 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
283 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
284 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
285
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
286 ## Restore shape
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
287 y = reshape (y, [szx(dperm), soutdim]);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
288 y = permute (y, [dperm, nd+1]);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
289 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
290
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
291 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
292
26249
78c4aadfbfd9 movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents: 26248
diff changeset
293 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
294
26253
339db43aa056 movfun.m: Implement "discard" option for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26251
diff changeset
295 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
296 y = NA (N, odim);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
297
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
298 ## 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
299 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
300
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
301 ## 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
302 if (! isempty (Cpre))
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
303 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
304 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
305 if (! isempty (Cpos))
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
306 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
307 endif
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
308
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
309 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
310
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
311 ## Apply "shrink" boundary conditions
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
312 ## 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
313 function y = shrink_bc (fcn, x, idxp, win, wlen, odim)
28945
6e460773bdda maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents: 28930
diff changeset
314
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
315 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
316 idx = idxp + win;
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
317 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
318
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 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
320 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
321 ## 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
322 ## 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
323 ## 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
324 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
325 k = idx(tf(:,i),i);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
326 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
327 endfor
28945
6e460773bdda maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents: 28930
diff changeset
328
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
329 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
330
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
331 ## 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
332 ## Window is padded at beginning and end with user-specified value.
28563
5a07c798eb08 avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents: 27985
diff changeset
333 function y = replaceval_bc (fcn, x, idxp, win, wlen, ~)
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
334
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
335 persistent substitute;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
336
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
337 ## 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
338 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
339 substitute = x;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
340 return;
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
341 endif
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
342
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
343 if (min (idxp) == 1)
26259
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
344 ## pre-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(1);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
347 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
348 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
349 else
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
350 ## post-pad window
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
351 sz = size (x);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
352 sz(1) = wlen(2);
3a8094a70193 movfun.m: Optimize subfunction replaceval_bc() for 33% speed improvement.
Rik <rik@octave.org>
parents: 26258
diff changeset
353 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
354 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
355 endif
26250
481708dbc540 movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents: 26249
diff changeset
356
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
357 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
358
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
359 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
360
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
361 ## Apply "same" boundary conditions
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
362 ## '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
363 ## boundary.
28563
5a07c798eb08 avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents: 27985
diff changeset
364 function y = same_bc (fcn, x, idxp, win, ~, ~)
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30236
diff changeset
365
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
366 idx = idxp + win;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
367 idx(idx < 1) = 1;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
368 N = length (x);
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
369 idx(idx > N) = N;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
370 y = fcn (x(idx));
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30236
diff changeset
371
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
372 endfunction
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
373
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
374 ## Apply "periodic" boundary conditions
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
375 ## 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
376 ## data from the other end of the array.
28563
5a07c798eb08 avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents: 27985
diff changeset
377 function y = periodic_bc (fcn, x, idxp, win, ~, ~)
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30236
diff changeset
378
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
379 N = length (x);
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
380 idx = idxp + win;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
381 tf = idx < 1;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
382 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
383 tf = idx > N;
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
384 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
385 y = fcn (x(idx));
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30236
diff changeset
386
26258
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
387 endfunction
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
388
26244
58b3107a00bc Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 26241
diff changeset
389
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 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
391 %! 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
392 %! 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
393 %! 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
394 %! 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
395 %! 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
396 %! 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
397 %! 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
398 %! 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
399 %! 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
400 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
401 %! h = plot (t, xn, "o;noisy signal;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
402 %! t, x, "-;true;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
403 %! t, x_s, "-;shrink;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
404 %! t, x_p, "-;periodic;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
405 %! t, x_m, "-;same;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
406 %! t, x_z, "-;zero;",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
407 %! t, x_f, "-;fill;");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
408 %! set (h(1), "markerfacecolor", "auto");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
409 %! set (h(2:end), "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
410 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
411 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
412 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
413 %! title ("moving mean with different boundary conditions");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
414 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
415 %! # 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
416 %! # 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
417
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
418 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
419 %! 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
420 %! 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
421 %! 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
422 %! 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
423 %! nwin = 5;
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
424 %! x_ = zeros (rows (x), nwin);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
425 %! wlen = 3 + (1:nwin) * 4;
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
426 %! for i = 1:nwin
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
427 %! 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
428 %! 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
429 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
430 %! h = plot (t, xn, "o",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
431 %! t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
432 %! t, x_, "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
433 %! set (h(1), "markerfacecolor", "auto");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
434 %! set (h(2:end), "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
435 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
436 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
437 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
438 %! title ({'moving mean with "periodic" boundary conditions',
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
439 %! "and windows of different lengths"});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
440 %! legend (h, {"noisy", "true", strsplit(num2str(wlen)){:}});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
441 %! #-----------------------------------------------------------------
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
442 %! # 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
443 %! # 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
444
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
445 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
446 %! 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
447 %! t = linspace (0,1,100).';
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
448 %! 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
449 %! y = movfun (@max, x, 15);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
450 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
451 %! h = plot (t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
452 %! t, y, "--");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
453 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
454 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
455 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
456 %! title ("moving max of several Gaussian functions");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
457 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
458 %! # Moving max of different Gaussian functions.
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
459 %! # 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
460
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
461 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
462 %! 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
463 %! 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
464 %! 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
465 %! 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
466 %! y = cos (w * t);
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
467 %! 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
468 %! ## 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
469 %! 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
470 %! y_ = y_ / w / dt;
26246
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 %! h = plot (t, x, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
473 %! t, y, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
474 %! t, y_, ":");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
475 %! set (h, "linewidth", 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
476 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
477 %! xlabel ("time");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
478 %! ylabel ("signal");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
479 %! 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
480 %! legend (h, {"sin", "cos", "[nb, na]"});
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
481 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
482 %! # 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
483 %! # 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
484
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
485 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
486 %! 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
487 %! 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
488 %! 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
489 %! 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
490 %! 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
491 %! 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
492 %! 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
493 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
494 %! st = movfun (@(y) (statistics (y)).', yn, wlen);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
495 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
496 %! h = plot (x, y, "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
497 %! x, yn, ".",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
498 %! x, st(:,[3 6]), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
499 %! x, st(:,6) + [-1 1].*st(:,7), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
500 %! x, st(:,[1 2 4 5]), "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
501 %! 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
502 %! set (h(5:end), "color", "k");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
503 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
504 %! xlabel ("x")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
505 %! ylabel ("y")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
506 %! title ("movfun() with Format 1 output data");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
507 %! legend (h, {"noiseless", "noisy", "mean", "median"})
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
508 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
509 %! # 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
510 %! # 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
511 %! # 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
512
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
513 %!demo
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
514 %! 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
515 %! 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
516 %! 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
517 %! 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
518 %! 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
519 %! 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
520 %! 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
521 %! 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
522 %!
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
523 %! fcn = @(y) [min(y), max(y)];
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
524 %! st = movfun (fcn, y, wlen);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
525 %!
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
526 %! h = plot (x, y, "o",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
527 %! x, squeeze (st(:,1,:)), "-",
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
528 %! x, squeeze (st(:,2,:)), "-");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
529 %! axis tight
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
530 %! 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
531 %! 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
532 %! xlabel ("x")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
533 %! ylabel ("y")
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
534 %! title ("movfun() with Format 2 output data");
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
535 %! legend (h(1:2), {"data1", "data2"})
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
536 %! #-----------------------------------------------------------------
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
537 %! # 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
538 %! # 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
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 %! x = (1:10).' + [-3, 0, 4];
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
542 %! ctrfun = @(x) x(2,:);
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
543 %! 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
544 %! for bc = valid_bc
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
545 %! 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
546 %! endfor
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
547 %! 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
548 %! 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
549
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 %!test
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
551 %! ## dim == 2, same as transpose
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
552 %! x = randi (10, 3);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
553 %! ctrfun = @(x) x(2,:);
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
554 %! valid_bc = {"periodic", 0, "fill", "same"};
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
555 %! for bc = valid_bc
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
556 %! 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
557 %! endfor
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
558 %! 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
559 %! 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
560
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
561 %!test
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
562 %! x = randi (10, 3, 10, 2);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
563 %! 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
564 %! assert (x, y);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
565
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
566 %!test
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
567 %! ## bad zero_bc
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
568 %! x = ones (10, 1);
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
569 %! 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
570 %! 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
571
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
572 ## Asymmetric windows
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
573 %!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
574 %! 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
575 %! wlen = [2, 1];
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
576 %! wlen02 = [0, 2];
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
577 %! wlen20 = [2, 0];
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
578 %! 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
579 %! 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
580
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
581 %!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
582 %!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
583 %!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
584 %!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
585 ## for shorter x, indexing fails
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
586 %!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
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, wlen, "Endpoints", "shrink"), 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, wlen02, "Endpoints", "shrink"), UNO)
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
590 %!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
591
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
592 %!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
593 %!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
594
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
595 %!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
596 %!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
597
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
598 %!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
599 %!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
600
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
601 %!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
602 %!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
603
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
604 ## Multidimensional output
26251
05ec27d632da movfun.m: Fix incorrect implementation of "fill" value for "Endpoints"
Rik <rik@octave.org>
parents: 26250
diff changeset
605 %!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
606 %!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
607 %! [10 5 2])
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
608 ## outdim > dim
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28896
diff changeset
609 %!error movfun (@(x) [min(x), max(x)], (1:10).', 3, "Outdim", 3)
26246
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
610
7adb62e4cc39 movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 26244
diff changeset
611 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28563
diff changeset
612 %!error <Invalid call> movfun ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28563
diff changeset
613 %!error <Invalid call> movfun (@min)
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28563
diff changeset
614 %!error <Invalid call> movfun (@min, 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 %!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
616 %!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
617 %!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
618 %!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
619 %!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
620 %!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
621 %! movfun (@min, 1, 3)
6cd1752f21e9 movslice.m, movfun.m: Eliminate duplicate input validation between these functions.
Rik <rik@octave.org>
parents: 26256
diff changeset
622 %!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
623 %! 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
624 %!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
625 %! 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
626 %!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
627 %! 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
628 ## 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
629 %!#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
630 %! movfun (@min, ones (6,3,4), 3, "outdim", 5);