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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
7 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
14 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
19 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
25
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
35 ## @tex
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
40 ## @end tex
6754
451b346d8c2f [project @ 2007-06-25 17:31:46 by jwe]
jwe
parents: 6046
diff changeset
41 ## @ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3408
diff changeset
42 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
43 ## @example
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
46 ## @end group
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
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
451b346d8c2f [project @ 2007-06-25 17:31:46 by jwe]
jwe
parents: 6046
diff changeset
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
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 3426
diff changeset
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
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 3426
diff changeset
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
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 3426
diff changeset
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
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 3426
diff changeset
73 ## @end table
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 3426
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
93 ## @end deftypefn
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
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
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
103
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
104 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
105
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
106
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
107 %!test
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
108 %! x = ones (10, 2);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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)