Mercurial > octave
annotate scripts/signal/movfun.m @ 26250:481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
* movfun.m: Write more documentation for "fill" value for "Endpoints" property.
Delete documentation for "zero" value. Add documentation for <user_value> as
a value for "Endpoints" property. Remove "zero" from list valid_bc of possible
bc functions. Change InputParser validation function for Endpoints to also
accept a numeric scalar in addition to valid_bc. Decode "Endpoints" property
and if it is numeric then initialize the replacement value in replaceval_bc
function. Replace "zero" in BIST tests with numeric value 0.
* movfun.m (replaceval_bc): New subfunction that replaces values in window
outside the original data with a specified value.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 16 Dec 2018 23:20:48 -0800 |
parents | 78c4aadfbfd9 |
children | 05ec27d632da |
rev | line source |
---|---|
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
|
1 ## Copyright (C) 2018 Juan Pablo Carbajal |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
2 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
3 ## This file is part of Octave. |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
4 ## |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
8 ## (at your option) any later version. |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
9 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
13 ## GNU General Public License for more details. |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
14 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
18 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
19 ## Author: Juan Pablo Carbajal <ajuanpi+dev@gmail.com> |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
20 ## Created: 2018-08-09 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
21 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
22 ## -*- texinfo -*- |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
23 ## @deftypefn {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{wlen}) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
24 ## @deftypefnx {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{[@var{nb}, @var{na}}]) |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
25 ## @deftypefnx {} {@var{y} =} movfun (@dots{}, @var{property}, @var{value}) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
26 ## 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
|
27 ## @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
|
28 ## |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
29 ## 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
|
30 ## window of length @var{wlen}. When @var{wlen} is an odd number the window is |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
31 ## symmetric and includes @code{(@var{wlen} - 1) / 2} elements on either side |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
32 ## of the central element. For example, when calculating the output at |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
33 ## index 5 with a window length of 3, @code{movfun} uses data elements |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
34 ## @code{[4, 5, 6]}. If @var{wlen} is an even number, the window is asymmetric |
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 ## and has @code{@var{wlen}/2} elements to the left of the central element |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
36 ## and @code{@var{wlen}/2 - 1} elements to the right of the central element. |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
37 ## For example, when calculating the output at index 5 with a window length of |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
38 ## 4, @code{movfun} uses data elements @code{[3, 4, 5, 6]}. |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
39 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
40 ## 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
|
41 ## the function is applied to a moving window @code{-@var{nb}:@var{na}}. This |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
42 ## window includes @var{nb} number of elements @strong{before} the current |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
43 ## element and @var{na} number of elements @strong{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
|
44 ## The current element is always included. For example, given |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
45 ## @code{@var{wlen} = [3, 0]}, the data used to calculate index 5 is |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
46 ## @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
|
47 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
48 ## 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
|
49 ## @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
|
50 ## Therefore, @var{fcn} must accept an array input argument and apply the |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
51 ## computation on the columns of that 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
|
52 ## |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
53 ## When applied to a column vector of length @var{n}, the function @var{fcn} |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
54 ## must return a @strong{row} vector of length @var{n}. |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
55 ## When applied to an array (possibly multi-dimensional) with @var{n} columns, |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
56 ## @var{fcn} may return a result in either of two formats: @w{Format 1)} |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
57 ## an array of size 1-by-@var{n}-by-@var{dim3}-by-@dots{}-by-@var{dimN}. This |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
58 ## is the typical output format from Octave core functions. Type |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
59 ## @code{demo ("movfun", 5)} for an example of this use case. |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
60 ## @w{Format 2)} a row vector of length |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
61 ## @code{@var{n} * @var{numel_higher_dims}} where @var{numel_higher_dims} is |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
62 ## @w{@code{prod (size (@var{x})(3:end))}}. The output of @var{fcn} for the |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
63 ## i-th input column must be found in the output at indices |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
64 ## @code{i:@var{n}:(@var{n}*@var{numel_higher_dims})}. |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
65 ## This format is useful when concatenating functions into arrays, or when |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
66 ## using @code{nthargout}. Type @code{demo ("movfun", 6)} for an example of |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
67 ## this case. |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
68 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
69 ## The calculation can be controlled by specifying @var{property}/@var{value} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
70 ## pairs. Valid properties are |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
71 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
72 ## @table @asis |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
73 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
74 ## @item @qcode{"dim"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
75 ## Operate along the dimension specified, rather than the default of the first |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
76 ## non-singleton dimension. |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
77 ## |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
78 ## @item @qcode{"Endpoints"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
79 ## |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
80 ## This property controls how results are calculated at the boundaries |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
81 ## (@w{endpoints}) of the window. Possible values are: |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
82 ## |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
83 ## @table @asis |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
84 ## @item @qcode{"shrink"} (default) |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
85 ## The window is truncated at the beginning and end of the array to include |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
86 ## only valid elements. For example, with a window of length 3, |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
87 ## @code{@var{y}(1) = @var{fcn} (@var{x}(1:2))}, and |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
88 ## @code{@var{y}(end) = @var{fcn} (@var{x}(end-1:end))}. |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
89 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
90 ## @item @qcode{"periodic"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
91 ## The window is wrapped around so that |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
92 ## @code{@var{y}(1) = @var{fcn} ([@var{x}(end-@var{k}:end), |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
93 ## @var{x}(1:@var{k})])}, where @var{k} is the radius of the window. For |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
94 ## example, with a window of length 3, |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
95 ## @code{@var{y}(1) = @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
|
96 ## |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
97 ## @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
|
98 ## 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
|
99 ## 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
|
100 ## @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
|
101 ## @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
|
102 ## 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
|
103 ## 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
|
104 ## 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
|
105 ## |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
106 ## @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
|
107 ## 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
|
108 ## 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
|
109 ## 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
|
110 ## @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
|
111 ## @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
|
112 ## 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
|
113 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
114 ## @item @qcode{"same"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
115 ## The resulting array @var{y} has the same values as @var{x} at the |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
116 ## 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
|
117 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
118 ## @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
|
119 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
120 ## Note that for some of these values, the window size at the boundaries is not |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
121 ## the same as in the middle part, and @var{fcn} must work with these 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
|
122 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
123 ## @item @qcode{"nancond"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
124 ## Controls whether @code{NaN} or @code{NA} values should be excluded (value: |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
125 ## @qcode{"omitnan"}), or included (value: @qcode{"includenan"}) in the |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
126 ## arguments passed to @var{fcn}. The default is @qcode{"omitnan"}. |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
127 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
128 ## @item @qcode{"outdim"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
129 ## 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
|
130 ## in the output @var{y}. This is only useful when @var{fcn} returns an |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
131 ## N-dimensinoal array in @w{Format 1}. The default is to return all output |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
132 ## 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
|
133 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
134 ## @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
|
135 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
136 ## 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
|
137 ## 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
|
138 ## 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
|
139 ## 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
|
140 ## 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
|
141 ## 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
|
142 ## 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
|
143 ## 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
|
144 ## 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
|
145 ## |
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
|
146 ## @example |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
147 ## @group |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
148 ## @var{fcn} = @@(x) basefcn (x)(:,size(x,2) * (@var{D}-1) + (1:size(x,2))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
149 ## @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
|
150 ## @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
|
151 ## @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
|
152 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
153 ## @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
|
154 ## @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
|
155 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
156 function y = movfun (fcn, x, wlen, varargin) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
157 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
158 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
|
159 print_usage (); |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
160 endif |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
161 |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
162 valid_bc = {"shrink", "periodic", "same", "fill"}; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
163 |
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
|
164 persistent dispatch; |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
165 if (isempty (dispatch)) |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
166 dispatch = struct (); |
2d80a065ce9a
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 for k = valid_bc |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
168 cmd = sprintf ("dispatch.%s = @%s_bc;", k{1}, k{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
|
169 eval (cmd); |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
170 endfor |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
171 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
|
172 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
173 ## Parse input arguments |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
174 parser = inputParser (); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
175 parser.FunctionName = "movfun"; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
176 parser.addParamValue ("Endpoints", "shrink", ... |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
177 @(x) any (strcmpi (x, valid_bc)) || (isscalar (x) && isnumeric (x))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
178 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
|
179 @(d) isempty (d) || (isscalar (d) && isindex (d, ndims (x)))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
180 parser.addParamValue ("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
|
181 @(x) any (strcmpi (x, {"omitnan", "includenan"}))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
182 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
|
183 @(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
|
184 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
185 parser.parse (varargin{:}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
186 bc = parser.Results.Endpoints; # boundary condition |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 clear parser |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
191 ## 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
|
192 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
193 ## If dim was not provided find the first non-singleton dimension. |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
194 szx = size (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
|
195 if (isempty (dim)) |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
196 (dim = find (szx > 1, 1)) || (dim = 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
|
197 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
|
198 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
199 ## Window length validation |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
200 if (! (isnumeric (wlen) && all (wlen >= 0) && fix (wlen) == wlen)) |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
201 error ("Octave:invalid-input-arg", |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
202 "movfun: WLEN must be a scalar or 2-element array of integers >= 0"); |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
203 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
|
204 if (isscalar (wlen)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
205 ## Check for proper window length |
26249
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
206 if (wlen == 1) |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
207 error ("Octave:invalid-input-arg", "movfun: WLEN must be > 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
|
208 endif |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
209 elseif (numel (wlen) == 2) |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
210 ## FIXME: Any further tests needed to validate form: wlen = [nb, na] ??? |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
211 else |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
212 error ("Octave:invalid-input-arg", |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
213 "movfun: WLEN must be a scalar or 2-element array of integers >= 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
|
214 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
|
215 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
216 ## Check that array is longer than WLEN at dimension DIM. At least one full |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
217 ## window must fit. Function max is used to include the case when WLEN is an |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
218 ## array. |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
219 ## FIXME: Consider using bc to decide what to do here. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
220 if (max (wlen) > szx(dim)) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
221 error ("Octave:invalid-input-arg", ... |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
222 "movfun: window length WLEN (%d) must be shorter than length along DIM%d (%d)", ... |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
223 max (wlen), dim, szx(dim)); |
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
|
224 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
|
225 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
226 ## Move the desired dim to the 1st dimension |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
227 nd = length (szx); # number of dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
228 dperm = [dim, 1:(dim-1), (dim+1):nd]; # permutation of dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
229 x = permute (x, dperm); # permute dim to first dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
230 ncols = prod (szx(dperm(2:end))); # rest dimensions as single column |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
231 N = szx(dperm(1)); # length of dim |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
232 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
|
233 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
234 ## 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
|
235 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
|
236 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
|
237 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
|
238 else |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
239 bcfunc = dispatch.(tolower (bc)); |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
240 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
|
241 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
242 ## Obtain slicer |
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
|
243 [slc, C, Cpre, Cpos, win] = movslice (N, wlen); |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
244 |
26249
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
245 ## 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
|
246 ## Validate that outdim makes sense |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
247 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
|
248 noutdim = length (tmp); # number of output dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
249 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
|
250 if (max (outdim) > noutdim) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
251 error ("Octave:invalid-input-arg", ... |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
252 "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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 endif |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
258 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
|
259 ## 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
|
260 if (noutdim > 1) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
261 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
|
262 else |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
263 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
|
264 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
|
265 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
266 ## Apply processing to each column |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
267 ## 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
|
268 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
|
269 parfor i = 1:ncols |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
274 ## Restore shape |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
275 y = reshape (y, [szx(dperm), soutdim]); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
276 y = permute (y, [dperm, nd+1]); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
277 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
|
278 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
279 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
|
280 |
26249
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
281 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
|
282 |
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
|
283 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
|
284 y = NA (N, odim); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
285 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
286 ## 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
|
287 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
|
288 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
289 ## 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
|
290 if (! isempty (Cpre)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
291 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
|
292 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
|
293 if (! isempty (Cpos)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
294 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
|
295 endif |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
296 |
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
|
297 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
|
298 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
299 ## Apply "shrink" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
300 ## 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
|
301 function y = shrink_bc (fcn, x, idxp, win, wlen, odim) |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
302 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
|
303 idx = idxp + win; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
304 tf = ! ((idx < 1) | (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
|
305 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
306 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
|
307 y = zeros (n, odim); |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
308 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
|
309 k = idx(tf(:,i),i); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
310 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
|
311 endfor |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
312 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
|
313 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
314 ## Apply "periodic" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
315 ## Data wraps around padding front of window with data from end of array and |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
316 ## vice versa. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
317 function y = periodic_bc (fcn, x, idxp, win) |
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 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
|
319 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
|
320 tf = idx < 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
|
321 idx(tf) = N + idx(tf); |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
322 tf = idx > 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
|
323 idx(tf) = idx(tf) - N; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
324 y = fcn (x(idx)); |
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
|
325 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
|
326 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
327 ## Apply "same" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
328 ## 'y' values outside window are set equal to 'x' values at the window |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
329 ## boundary. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
330 function y = same_bc (fcn, x, idxp, win) |
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
|
331 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
|
332 idx(idx < 1) = 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
|
333 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
|
334 idx(idx > N) = N; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
335 y = fcn (x(idx)); |
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
|
336 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
|
337 |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
338 ## 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
|
339 ## Window is padded at beginning and end with user-specified value. |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
340 function y = replaceval_bc (fcn, x, idxp, win, wlen) |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
341 |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
342 persistent substitute; |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
343 |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
344 ## 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
|
345 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
|
346 substitute = x; |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
347 return; |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
348 endif |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
349 |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
350 ## Pad beginning and end of window with specified value. |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
351 if (isscalar (wlen)) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
352 wlen = [wlen, 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
|
353 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
|
354 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
|
355 if (min (idxp) == 1) |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
356 x = prepad (x, N + wlen(1), substitute); |
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
|
357 idx = idxp + win + wlen(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
|
358 elseif (max (idxp) == N) |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
359 x = postpad (x, N + wlen(2), substitute); |
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
|
360 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
|
361 endif |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
362 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
363 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
|
364 |
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
|
365 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
|
366 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
367 ## Apply "fill" 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
|
368 ## FIXME: This is incorrect. This directly changes the output when it |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
369 ## must only change the values that @fcn considers. Some functions do not |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
370 ## return NaN when there are NaN inputs such as "min (NaN, 5)". |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
371 ## Window is padded at beginning and end with NaN |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
372 function y = fill_bc (fcn, x, idxp, win, wlen, odim) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
373 y = NaN (length (idxp), 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
|
374 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
|
375 |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
376 |
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
|
377 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
378 %! 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
|
379 %! 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
|
380 %! 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
|
381 %! 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
|
382 %! 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
|
383 %! 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
|
384 %! 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
|
385 %! 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
|
386 %! 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
|
387 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
388 %! h = plot (t, xn, "o;noisy signal;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
389 %! t, x, "-;true;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
390 %! t, x_s, "-;shrink;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
391 %! t, x_p, "-;periodic;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
392 %! t, x_m, "-;same;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
393 %! t, x_z, "-;zero;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
394 %! t, x_f, "-;fill;"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
395 %! set (h(1), "markerfacecolor", "auto"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
396 %! set (h(2:end), "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
397 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
398 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
399 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
400 %! title ("moving mean with different boundary conditions"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
401 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
402 %! # 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
|
403 %! # 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
|
404 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
405 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
406 %! 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
|
407 %! 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
|
408 %! 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
|
409 %! 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
|
410 %! nwin = 5; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
411 %! x_ = zeros (rows (x), nwin); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
412 %! wlen = 3 + (1:nwin) * 4; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
413 %! for i = 1:nwin |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
414 %! 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
|
415 %! 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
|
416 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
417 %! h = plot (t, xn, "o", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
418 %! t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
419 %! t, x_, "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
420 %! set (h(1), "markerfacecolor", "auto"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
421 %! set (h(2:end), "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
422 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
423 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
424 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
425 %! title ({'moving mean with "periodic" boundary conditions', |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
426 %! "and windows of different lengths"}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
427 %! legend (h, {"noisy", "true", strsplit(num2str(wlen)){:}}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
428 %! #----------------------------------------------------------------- |
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 %! # 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
|
430 %! # 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
|
431 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
432 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
433 %! 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
|
434 %! t = linspace (0,1,100).'; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
435 %! 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
|
436 %! y = movfun (@max, x, 15); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
437 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
438 %! h = plot (t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
439 %! t, y, "--"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
440 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
441 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
442 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
443 %! title ("moving max of several Gaussian functions"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
444 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
445 %! # Moving max of different Gaussian functions. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
446 %! # 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
|
447 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
448 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
449 %! 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
|
450 %! 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
|
451 %! 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
|
452 %! 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
|
453 %! y = cos (w * t); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
454 %! 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
|
455 %! ## 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
|
456 %! 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
|
457 %! y_ = y_ / w / dt; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
458 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
459 %! h = plot (t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
460 %! t, y, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
461 %! t, y_, ":"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
462 %! set (h, "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
463 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
464 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
465 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
466 %! 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
|
467 %! legend (h, {"sin", "cos", "[nb, na]"}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
468 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
469 %! # 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
|
470 %! # 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
|
471 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
472 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
473 %! 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
|
474 %! 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
|
475 %! 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
|
476 %! 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
|
477 %! 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
|
478 %! 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
|
479 %! 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
|
480 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
481 %! st = movfun (@(y) (statistics (y)).', yn, wlen); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
482 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
483 %! h = plot (x, y, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
484 %! x, yn, ".", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
485 %! x, st(:,[3 6]), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
486 %! x, st(:,6) + [-1 1].*st(:,7), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
487 %! x, st(:,[1 2 4 5]), "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
488 %! 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
|
489 %! set (h(5:end), "color", "k"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
490 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
491 %! xlabel ("x") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
492 %! ylabel ("y") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
493 %! title ("movfun() with Format 1 output data"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
494 %! legend (h, {"noiseless", "noisy", "mean", "median"}) |
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 %! # 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
|
497 %! # 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
|
498 %! # 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
|
499 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
500 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
501 %! 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
|
502 %! 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
|
503 %! 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
|
504 %! 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
|
505 %! 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
|
506 %! 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
|
507 %! 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
|
508 %! 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
|
509 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
510 %! fcn = @(y) [min(y), max(y)]; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
511 %! st = movfun (fcn, y, wlen); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
512 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
513 %! h = plot (x, y, "o", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
514 %! x, squeeze (st(:,1,:)), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
515 %! x, squeeze (st(:,2,:)), "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
516 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
517 %! 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
|
518 %! 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
|
519 %! xlabel ("x") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
520 %! ylabel ("y") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
521 %! title ("movfun() with Format 2 output data"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
522 %! legend (h(1:2), {"data1", "data2"}) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
523 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
524 %! # 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
|
525 %! # 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
|
526 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
527 %!test |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
528 %! x = (1:10).' + [-3, 0, 4]; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
529 %! ctrfun = @(x) x(2,:); |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
530 %! valid_bc = {"same", "periodic", 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
|
531 %! for bc = valid_bc |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
532 %! 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
|
533 %! endfor |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
534 %! x_ = x; x_([1 end],:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
535 %! assert (movfun (ctrfun, x, 3, "Endpoints", "fill"), x_); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
536 %! 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
|
537 %! 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
|
538 |
2d80a065ce9a
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 %!test |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
540 %! ## dim == 2, same as transpose |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
541 %! x = randi (10, 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
542 %! ctrfun = @(x) x(2,:); |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
543 %! valid_bc = {"same", "periodic", 0}; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
544 %! for bc = valid_bc |
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}, "dim", 2), x.'); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
546 %! endfor |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
547 %! x_ = x; x_([1 end],:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
548 %! assert (movfun (ctrfun, x.', 3, "Endpoints", "fill", "dim", 2), x_.'); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
549 %! 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
|
550 %! 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
|
551 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
552 %!test |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
553 %! x = randi (10, 3, 10, 2); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
554 %! 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
|
555 %! assert (x, y); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
556 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
557 %!test |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
558 %! ## bad zero_bc |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
559 %! x = ones (10, 1); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
560 %! 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
|
561 %! 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
|
562 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
563 ## Asymmetric windows |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
564 %!shared x,wlen,wlen0b,wlen0f,ctrfun,xd,UNO,UNOd0b,UNOd0f |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
565 %! x = (1:10).' + [-3, 0, 4]; |
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
|
566 %! wlen = [2 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
|
567 %! wlen0b = [0 2]; |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
568 %! wlen0f = [2 0]; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
569 %! ctrfun = @(x) x(wlen(1)+1,:); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
570 %! xd = x; xd([1:2 end],:) = NaN; |
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 %! UNO = ones (7,1); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
572 %! UNOd0b = UNOd0f = UNO; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
573 %! UNOd0b(end-1:end,:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
574 %! UNOd0f(1:2,:) = NaN; |
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
|
575 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
576 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "same"), x) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
577 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "fill"), xd) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
578 %!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
|
579 %!assert (movfun (ctrfun, x, wlen, "Endpoints", 0), x) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
580 ## for shorter x, indexing fails |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
581 %!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
|
582 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
583 %!assert (movfun (@min, UNO, wlen0b, "Endpoints", "same"), UNO) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
584 %!assert (movfun (@min, UNO, wlen0f, "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
|
585 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
586 %!assert (movfun (@min, UNO, wlen, "Endpoints", "shrink"), UNO) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
587 %!assert (movfun (@min, UNO, wlen0b, "Endpoints", "shrink"), UNO) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
588 %!assert (movfun (@min, UNO, wlen0f, "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
|
589 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
590 %!assert (movfun (@min, UNO, wlen0b, "Endpoints", "fill"), UNOd0b) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
591 %!assert (movfun (@min, UNO, wlen0f, "Endpoints", "fill"), UNOd0f) |
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
|
592 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
593 %!assert (movfun (@min, UNO, wlen0b, "Endpoints", "periodic"), UNO) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
594 %!assert (movfun (@min, UNO, wlen0f, "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
|
595 |
26250
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
596 %!assert (movfun (@max, UNO, wlen0b, "Endpoints", 0), UNO) |
481708dbc540
movfun.m: Implement <numeric scalar> as value for "Endpoints" property for Matlab compatibility.
Rik <rik@octave.org>
parents:
26249
diff
changeset
|
597 %!assert (movfun (@max, UNO, wlen0f, "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
|
598 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
599 ## Multidimensional output |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
600 %!assert(size(movfun (@(x)[min(x) max(x)], (1:10).', 3)), [10 2]) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
601 %!assert(size(movfun (@(x)[min(x) max(x)], cumsum(ones(10,5),2), 3)), [10 5 2]) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
602 ## outdim > dim |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
603 %!error (movfun (@(x) [min(x), max(x)], (1:10).', 3, "Outdim", 3)) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
604 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
605 ## Test input validation |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
606 %!error movfun () |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
607 %!error movfun (@min) |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
608 %!error movfun (@min, 1) |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
609 %!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
|
610 %!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
|
611 %!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
|
612 %!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
|
613 %!error <WLEN must be a scalar or 2-element array> movfun (@min, 1, [1, 2, 3]) |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
614 %!error <WLEN \(3\) must be shorter than length along DIM1 \(1\)> |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
615 %! movfun (@min, 1, 3); |
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 \(4\) must be shorter than length along DIM1 \(1\)> |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
617 %! movfun (@min, 1, [4, 1]); |
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 \(5\) must be shorter than length along DIM1 \(1\)> |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
619 %! 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
|
620 ## 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
|
621 %!#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
|
622 %! movfun (@min, ones (6,3,4), 3, "outdim", 5); |