Mercurial > octave
annotate scripts/statistics/std.m @ 30997:5330efaf9476
Add optional second output to var and std (bug #62395)
* scripts/statistics/var.m: Add optional second output containing the mean
used to calculate the variance. Move weight isempty check ahead of vector
dimension isscalar check to avoid triggering incompatability error. Add BISTs
testing second output with different calling options. Add BIST testing empty
value passed as variance weight treated as zero. Add new output behavior to
docstring, and update function definitions to show the primary variable.
* scripts/statistics/std.m: Add passthrough for second output from var when
std called with two outputs. Add BISTs testing second output with different
calling options. Update docstring noting new output behavior.
* etc/NEWS.8.md: Note output changes to var and std under Matlab Compatability.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Thu, 12 May 2022 13:10:52 -0400 |
parents | 5d3faba0342e |
children | 1bf26f913b9c |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30410
diff
changeset
|
3 ## Copyright (C) 1996-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3200 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3200 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
3200 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
3200 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3200 | 25 |
3367 | 26 ## -*- texinfo -*- |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{y} =} std (@var{x}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
28 ## @deftypefnx {} {@var{y} =} std (@var{x}, @var{w}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
29 ## @deftypefnx {} {@var{y} =} std (@var{x}, @var{w}, @var{dim}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
30 ## @deftypefnx {} {@var{y} =} std (@var{x}, @var{w}, @qcode{"ALL"}) |
30997
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
31 ## @deftypefnx {} {[@var{y}, @var{mu}] =} std (@dots{}) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
32 ## Compute the standard deviation of the elements of the vector @var{x}. |
20174
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
33 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
34 ## The standard deviation is defined as |
3367 | 35 ## @tex |
36 ## $$ | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
37 ## {\rm std} (x) = \sigma = \sqrt{{\sum_{i=1}^N (x_i - \bar{x})^2 \over N - 1}} |
3367 | 38 ## $$ |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
39 ## where $\bar{x}$ is the mean value of @var{x} and $N$ is the number of elements of @var{x}. |
3367 | 40 ## @end tex |
6754 | 41 ## @ifnottex |
3426 | 42 ## |
3367 | 43 ## @example |
44 ## @group | |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
45 ## std (@var{x}) = sqrt ( 1/(N-1) SUM_i (@var{x}(i) - mean(@var{x}))^2 ) |
3367 | 46 ## @end group |
47 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
48 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
49 ## @noindent |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
50 ## where @math{N} is the number of elements of the @var{x} vector. |
6754 | 51 ## @end ifnottex |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 ## |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
53 ## If @var{x} is an array, compute the standard deviation for each column and |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
54 ## return them in a row vector (or for an n-D array, the result is returned as |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
55 ## an array of dimension 1 x n x m x @dots{}). |
4844 | 56 ## |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
57 ## The optional argument @var{w} determines the weighting scheme to use. Valid |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
58 ## values are: |
4844 | 59 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
60 ## @table @asis |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
61 ## @item 0 [default]: |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
62 ## Normalize with @math{N-1}. This provides the square root of the best |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
63 ## unbiased estimator of the variance. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
64 ## |
4844 | 65 ## @item 1: |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
66 ## Normalize with @math{N}. This provides the square root of the second moment |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
67 ## around the mean. |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
68 ## |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
69 ## @item a vector: |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
70 ## Compute the weighted standard deviation with nonnegative scalar weights. The |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
71 ## length of @var{w} must be equal to the size of @var{x} along dimension |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
72 ## @var{dim}. |
4844 | 73 ## @end table |
74 ## | |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
75 ## If @math{N} is equal to 1 the value of @var{W} is ignored and |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
76 ## normalization by @math{N} is used. |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
77 ## |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
78 ## The optional variable @var{dim} forces @code{std} to operate over the |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
79 ## specified dimension. @var{dim} can either be a scalar dimension or a vector |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
80 ## of non-repeating dimensions over which to operate. Dimensions must be |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
81 ## positive integers, and the standard deviation is calculated over the array |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
82 ## slice defined by @var{dim}. |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
83 ## |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
84 ## Specifying dimension @qcode{"ALL"} will force @code{std} to operate on all |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
85 ## elements of @var{x}, and is equivalent to @code{std (@var{x}(:))}. |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
86 ## |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
87 ## When @var{dim} is a vector or @qcode{"ALL"}, @var{w} must be either 0 or 1. |
30997
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
88 ## |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
89 ## If requested the optional second output variable @var{mu} will contain the |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
90 ## mean or weighted mean used to calcluate @var{y}, and will be the same size |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
91 ## as @var{y}. |
24584
7a18e02a516e
mad.m: New function to calculate mean or median absolute deviation.
Rik <rik@octave.org>
parents:
24574
diff
changeset
|
92 ## @seealso{var, bounds, mad, range, iqr, mean, median} |
3367 | 93 ## @end deftypefn |
3200 | 94 |
30997
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
95 function [y, mu] = std (varargin) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
96 |
30997
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
97 if (nargout < 2) |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
98 y = sqrt (var (varargin{:})); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
99 else |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
100 [y, mu] = var (varargin{:}); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
101 y = sqrt (y); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
102 endif |
3200 | 103 |
104 endfunction | |
7411 | 105 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
106 |
7411 | 107 %!test |
108 %! x = ones (10, 2); | |
109 %! y = [1, 3]; | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14336
diff
changeset
|
110 %! assert (std (x), [0, 0]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14336
diff
changeset
|
111 %! assert (std (y), sqrt (2), sqrt (eps)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14336
diff
changeset
|
112 %! assert (std (x, 0, 2), zeros (10, 1)); |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
113 |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
114 %!assert (std (ones (3, 1, 2), 0, 2), zeros (3, 1, 2)) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
115 %!assert (std ([1 2], 0), sqrt (2)/2, 5*eps) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
116 %!assert (std ([1 2], 1), 0.5, 5*eps) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
117 %!assert (std (1), 0) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
118 %!assert (std (single (1)), single (0)) |
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
119 %!assert (std ([1 2 3], [], 3), [0 0 0]) |
7411 | 120 |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
121 ##Test empty inputs |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
122 %!assert (std ([]), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
123 %!assert (std ([],[],1), NaN(1,0)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
124 %!assert (std ([],[],2), NaN(0,1)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
125 %!assert (std ([],[],3), []) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
126 %!assert (std (ones (0,1)), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
127 %!assert (std (ones (1,0)), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
128 %!assert (std (ones (1,0), [], 1), NaN(1,0)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
129 %!assert (std (ones (1,0), [], 2), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
130 %!assert (std (ones (1,0), [], 3), NaN(1,0)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
131 %!assert (std (ones (0,1)), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
132 %!assert (std (ones (0,1), [], 1), NaN) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
133 %!assert (std (ones (0,1), [], 2), NaN(0,1)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
134 %!assert (std (ones (0,1), [], 3), NaN(0,1)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
135 %!assert (std (ones (1,3,0,2)), NaN(1,1,0,2)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
136 %!assert (std (ones (1,3,0,2), [], 1), NaN(1,3,0,2)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
137 %!assert (std (ones (1,3,0,2), [], 2), NaN(1,1,0,2)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
138 %!assert (std (ones (1,3,0,2), [], 3), NaN(1,3,1,2)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
139 %!assert (std (ones (1,3,0,2), [], 4), NaN(1,3,0)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
140 |
30997
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
141 ##Test second output |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
142 %!test <*62395> |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
143 %! [~, m] = std (1); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
144 %! assert (m, 1); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
145 %! [~, m] = std ([1,2,3; 3,2,1]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
146 %! assert (m, [2,2,2]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
147 %! [~, m] = std ([]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
148 %! assert (m, NaN); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
149 %! [~, m] = std ([1 2 3], 0); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
150 %! assert (m, 2); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
151 %! [~, m] = std ([1 2 3], 1); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
152 %! assert (m, 2); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
153 %! [~, m] = std ([1 2 3], [1 2 3]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
154 %! assert (m, 7/3, eps); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
155 %! [~, m] = std ([1 2 3], [], 1); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
156 %! assert (m, [1 2 3]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
157 %! [~, m] = std ([1 2 3; 1,2,3], [], [1 2]); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
158 %! assert (m, 2); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
159 %! [~, m] = std ([1 2 3; 1,2,3], [], "all"); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
160 %! assert (m, 2); |
5330efaf9476
Add optional second output to var and std (bug #62395)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30875
diff
changeset
|
161 |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
162 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
163 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
164 %!error <Invalid call> std () |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
165 %!error <X must be a numeric> std (['A'; 'B']) |
30410
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
166 %!error <W must be 0> std ([1 2], 2) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
167 %!error <DIM must be a positive integer> std (1, [], ones (2,2)) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
168 %!error <DIM must be a positive integer> std (1, [], 1.5) |
bc0de453fb6a
extend var and std with dim options (bug #58116) and weights (patch #10103)
Stefano Guidoni <ilguido@users.sf.net>
parents:
29359
diff
changeset
|
169 %!error <DIM must be a positive integer> std (1, [], 0) |