Mercurial > octave
annotate scripts/signal/movfun.m @ 26249:78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
* movfun.m: Rewrite documentation about scalar window length WLEN and provide
many example usages. Remove input validation check for symmetric window.
Remove BIST test checking for error when given an asymmetric WLEN.
* movslice.m: Remove input validation check for symmetric window.
Detect whether scalar WLEN is even or odd. Add new calculation
for indices of asymmetric window. Remove BIST test checking for error when
given an asymmetric WLEN.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 16 Dec 2018 22:24:10 -0800 |
parents | 8a0778f549e8 |
children | 481708dbc540 |
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 |
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
34 ## @code{[4, 5, 6]. If @var{wlen} is an even number, the window is asymmetric |
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 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
97 ## @item @qcode{"zero"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
98 ## The array is pre-padded and post-padded with zeros to exactly contain the |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
99 ## window. 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
|
100 ## @code{@var{y}(1) = @var{fcn} ([0, @var{x}(1:2)])}, and |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
101 ## @code{@var{y}(end) = @var{fcn} ([@var{x}(end-1:end), 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
|
102 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
103 ## @item @qcode{"same"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
104 ## 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
|
105 ## 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
|
106 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
107 ## @item @qcode{"fill"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
108 ## The resulting array @var{y} has @code{NaN} at the 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
|
109 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
110 ## @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
|
111 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
112 ## 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
|
113 ## 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
|
114 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
115 ## @item @qcode{"nancond"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
116 ## 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
|
117 ## @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
|
118 ## 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
|
119 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
120 ## @item @qcode{"outdim"} |
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
121 ## 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
|
122 ## 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
|
123 ## 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
|
124 ## 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
|
125 ## |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
126 ## @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
|
127 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
128 ## 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
|
129 ## 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
|
130 ## 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
|
131 ## 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
|
132 ## 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
|
133 ## 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
|
134 ## 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
|
135 ## 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
|
136 ## 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
|
137 ## |
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
|
138 ## @example |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
139 ## @group |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
140 ## @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
|
141 ## @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
|
142 ## @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
|
143 ## @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
|
144 ## |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
145 ## @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
|
146 ## @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
|
147 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
148 function y = movfun (fcn, x, wlen, varargin) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
149 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
150 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
|
151 print_usage (); |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
152 endif |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
153 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
154 valid_bc = {"shrink", "periodic", "same", "zero", "fill"}; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
155 |
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
|
156 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
|
157 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
|
158 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
|
159 for k = valid_bc |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
165 ## Parse input arguments |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
166 parser = inputParser (); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
167 parser.FunctionName = "movfun"; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
168 parser.addParamValue ("Endpoints", "shrink", ... |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
169 @(x) any (strcmpi (x, valid_bc))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
170 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
|
171 @(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
|
172 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
|
173 @(x) any (strcmpi (x, {"omitnan", "includenan"}))); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
174 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
|
175 @(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
|
176 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
177 parser.parse (varargin{:}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
178 bc = parser.Results.Endpoints; # boundary condition |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 clear parser |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
183 ## 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
|
184 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
185 ## 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
|
186 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
|
187 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
|
188 (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
|
189 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
|
190 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
191 ## 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
|
192 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
|
193 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
|
194 "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
|
195 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
|
196 if (isscalar (wlen)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
197 ## 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
|
198 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
|
199 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
|
200 endif |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
201 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
|
202 ## 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
|
203 else |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
204 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
|
205 "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
|
206 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
|
207 |
26248
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
208 ## 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
|
209 ## window must fit. Function max is used to include the case when WLEN is an |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
210 ## array. |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
211 ## 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
|
212 if (max (wlen) > szx(dim)) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
213 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
|
214 "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
|
215 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
|
216 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
|
217 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
218 ## 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
|
219 nd = length (szx); # number of dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 N = szx(dperm(1)); # length of dim |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
224 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
|
225 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
226 ## Obtain function for boundary conditions |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
227 bcfunc = dispatch.(tolower (bc)); |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
228 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
229 ## 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
|
230 [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
|
231 |
26249
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
232 ## 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
|
233 ## Validate that outdim makes sense |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
234 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
|
235 noutdim = length (tmp); # number of output dimensions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
236 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
|
237 if (max (outdim) > noutdim) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
238 error ("Octave:invalid-input-arg", ... |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
239 "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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 endif |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
245 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
|
246 ## 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
|
247 if (noutdim > 1) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
248 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
|
249 else |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
250 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
|
251 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
|
252 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
253 ## Apply processing to each column |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
254 ## 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
|
255 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
|
256 parfor i = 1:ncols |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
261 ## Restore shape |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
262 y = reshape (y, [szx(dperm), soutdim]); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
263 y = permute (y, [dperm, nd+1]); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
264 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
|
265 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
266 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
|
267 |
26249
78c4aadfbfd9
movfun.m, movslice.m: Add support for even-size, asymmetric windows for Matlab compatibility.
Rik <rik@octave.org>
parents:
26248
diff
changeset
|
268 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
|
269 |
26241
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
270 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
|
271 y = NA (N, odim); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
272 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
273 ## 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
|
274 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
|
275 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
276 ## 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
|
277 if (! isempty (Cpre)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
278 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
|
279 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
|
280 if (! isempty (Cpos)) |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
281 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
|
282 endif |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
283 |
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
|
284 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
|
285 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
286 ## Apply "shrink" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
287 ## 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
|
288 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
|
289 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
|
290 idx = idxp + win; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
291 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
|
292 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 k = idx(tf(:,i),i); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
301 ## Apply "periodic" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
302 ## 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
|
303 ## vice versa. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 idx(tf) = idx(tf) - N; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
311 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
|
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 "same" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
315 ## '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
|
316 ## boundary. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 idx(idx > N) = N; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
322 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
|
323 endfunction |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
324 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
325 ## Apply "zero" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
326 ## Window is padded at beginning and end with zeros |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
327 function y = zero_bc (fcn, x, idxp, win, wlen) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
328 if (isscalar (wlen)) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 if (min (idxp) == 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 x = prepad (x, N + 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
|
334 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
|
335 elseif (max (idxp) == 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
|
336 x = postpad (x, N + wlen(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
|
337 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
|
338 endif |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
339 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
|
340 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
|
341 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
342 ## Apply "fill" boundary conditions |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
343 ## 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
|
344 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
|
345 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
|
346 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
|
347 |
26244
58b3107a00bc
Update documentation for movXXX functions (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
26241
diff
changeset
|
348 |
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
|
349 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
350 %! 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
|
351 %! 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
|
352 %! 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
|
353 %! 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
|
354 %! 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
|
355 %! 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
|
356 %! x_m = movfun (@mean, xn, 5, "Endpoints", "same"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
357 %! x_z = movfun (@mean, xn, 5, "Endpoints", "zero"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
358 %! 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
|
359 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
360 %! h = plot (t, xn, "o;noisy signal;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
361 %! t, x, "-;true;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
362 %! t, x_s, "-;shrink;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
363 %! t, x_p, "-;periodic;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
364 %! t, x_m, "-;same;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
365 %! t, x_z, "-;zero;", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
366 %! t, x_f, "-;fill;"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
367 %! set (h(1), "markerfacecolor", "auto"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
368 %! set (h(2:end), "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
369 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
370 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
371 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
372 %! title ("moving mean with different boundary conditions"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
373 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
374 %! # 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
|
375 %! # 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
|
376 |
2d80a065ce9a
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 %! nwin = 5; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
383 %! x_ = zeros (rows (x), nwin); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
384 %! wlen = 3 + (1:nwin) * 4; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
385 %! for i = 1:nwin |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
386 %! 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
|
387 %! 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
|
388 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
389 %! h = plot (t, xn, "o", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
390 %! t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
391 %! t, x_, "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
392 %! set (h(1), "markerfacecolor", "auto"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
393 %! set (h(2:end), "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
394 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
395 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
396 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
397 %! title ({'moving mean with "periodic" boundary conditions', |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
398 %! "and windows of different lengths"}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
399 %! legend (h, {"noisy", "true", strsplit(num2str(wlen)){:}}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
400 %! #----------------------------------------------------------------- |
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
|
401 %! # 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
|
402 %! # 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
|
403 |
2d80a065ce9a
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 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
405 %! 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
|
406 %! t = linspace (0,1,100).'; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
407 %! 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
|
408 %! y = movfun (@max, x, 15); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
409 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
410 %! h = plot (t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
411 %! t, y, "--"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
412 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
413 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
414 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
415 %! title ("moving max of several Gaussian functions"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
416 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
417 %! # Moving max of different Gaussian functions. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
418 %! # 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
|
419 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
420 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
421 %! 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
|
422 %! 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
|
423 %! 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
|
424 %! 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
|
425 %! y = cos (w * t); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
426 %! 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
|
427 %! ## 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
|
428 %! 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
|
429 %! y_ = y_ / w / dt; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
430 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
431 %! h = plot (t, x, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
432 %! t, y, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
433 %! t, y_, ":"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
434 %! set (h, "linewidth", 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
435 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
436 %! xlabel ("time"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
437 %! ylabel ("signal"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
438 %! title ("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
|
439 %! legend (h, {"sin", "cos", "[nb, na]"}); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
440 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
441 %! # 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
|
442 %! # 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
|
443 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
444 %!demo |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
445 %! 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
|
446 %! 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
|
447 %! 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
|
448 %! 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
|
449 %! 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
|
450 %! 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
|
451 %! 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
|
452 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
453 %! st = movfun (@(y) (statistics (y)).', yn, wlen); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
454 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
455 %! h = plot (x, y, "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
456 %! x, yn, ".", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
457 %! x, st(:,[3 6]), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
458 %! x, st(:,6) + [-1 1].*st(:,7), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
459 %! x, st(:,[1 2 4 5]), "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
460 %! 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
|
461 %! set (h(5:end), "color", "k"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
462 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
463 %! xlabel ("x") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
464 %! ylabel ("y") |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
465 %! title ("movfun() with Format 1 output data"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
466 %! legend (h, {"noiseless", "noisy", "mean", "median"}) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
467 %! #----------------------------------------------------------------- |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
468 %! # 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
|
469 %! # 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
|
470 %! # 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
|
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 = 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
|
475 %! 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
|
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 %! 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
|
480 %! 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
|
481 %! |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
482 %! fcn = @(y) [min(y), max(y)]; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
483 %! st = movfun (fcn, y, wlen); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
484 %! |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
485 %! h = plot (x, y, "o", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
486 %! x, squeeze (st(:,1,:)), "-", |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
487 %! x, squeeze (st(:,2,:)), "-"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
488 %! axis tight |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
489 %! 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
|
490 %! 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
|
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 2 output data"); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
494 %! legend (h(1:2), {"data1", "data2"}) |
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 min() and max() on the same window. |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
497 %! # 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
|
498 |
2d80a065ce9a
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 %!test |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
500 %! x = (1:10).' + [-3, 0, 4]; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
501 %! ctrfun = @(x) x(2,:); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
502 %! valid_bc = {"same", "periodic", "zero"}; |
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
|
503 %! for bc = valid_bc |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
504 %! 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
|
505 %! endfor |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
506 %! x_ = x; x_([1 end],:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
507 %! 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
|
508 %! 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
|
509 %! 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
|
510 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
511 %!test |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
512 %! ## dim == 2, same as transpose |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
513 %! x = randi (10, 3); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
514 %! ctrfun = @(x) x(2,:); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
515 %! valid_bc = {"same", "periodic", "zero"}; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
516 %! for bc = valid_bc |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
517 %! 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
|
518 %! endfor |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
519 %! x_ = x; x_([1 end],:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
520 %! 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
|
521 %! 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
|
522 %! 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
|
523 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
524 %!test |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
525 %! x = randi (10, 3, 10, 2); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
526 %! 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
|
527 %! assert (x, y); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
528 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
529 %!test |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
530 %! ## bad zero_bc |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
531 %! x = ones (10, 1); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
532 %! y = x; y(1:2) = y([end end-1]) = [0.6;0.8]; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
533 %! assert (movfun (@mean, x, 5, "Endpoints", "zero"), 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
|
534 |
2d80a065ce9a
Add functions for calculating value of function handle over windows of data (bug #48774).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
diff
changeset
|
535 ## Asymmetric windows |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
536 %!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
|
537 %! 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
|
538 %! 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
|
539 %! 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
|
540 %! wlen0f = [2 0]; |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
541 %! ctrfun = @(x) x(wlen(1)+1,:); |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
542 %! 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
|
543 %! UNO = ones (7,1); |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
544 %! UNOd0b = UNOd0f = UNO; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
545 %! UNOd0b(end-1:end,:) = NaN; |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
546 %! 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
|
547 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
548 %!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
|
549 %!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
|
550 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "periodic"), x) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
551 %!assert (movfun (ctrfun, x, wlen, "Endpoints", "zero"), x) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
552 ## for shorter x, indexing fails |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
553 %!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
|
554 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
555 %!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
|
556 %!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
|
557 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
558 %!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
|
559 %!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
|
560 %!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
|
561 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
562 %!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
|
563 %!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
|
564 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
565 %!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
|
566 %!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
|
567 |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
568 %!assert (movfun (@max, UNO, wlen0b, "Endpoints", "zero"), UNO) |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
569 %!assert (movfun (@max, UNO, wlen0f, "Endpoints", "zero"), 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
|
570 |
2d80a065ce9a
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 ## Multidimensional output |
26246
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
572 %!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
|
573 %!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
|
574 ## outdim > dim |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
575 %!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
|
576 |
7adb62e4cc39
movfun.m, movslice.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
26244
diff
changeset
|
577 ## 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
|
578 %!error movfun () |
8a0778f549e8
movfun.m, movslice.m: Add additional input validation and BIST tests for same.
Rik <rik@octave.org>
parents:
26246
diff
changeset
|
579 %!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
|
580 %!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
|
581 %!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
|
582 %!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
|
583 %!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
|
584 %!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
|
585 %!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
|
586 %!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
|
587 %! 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
|
588 %!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
|
589 %! 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
|
590 %!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
|
591 %! 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
|
592 ## 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
|
593 %!#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
|
594 %! movfun (@min, ones (6,3,4), 3, "outdim", 5); |