annotate scripts/general/isscalar.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents e98140f84ae0
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14039
diff changeset
1 ## Copyright (C) 1996-2012 John W. Eaton
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
2 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
4 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
8 ## your option) any later version.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
9 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
14 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
15 ## 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: 6967
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
18
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
20 ## @deftypefn {Function File} {} isscalar (@var{x})
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
21 ## Return true if @var{x} is a scalar.
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
22 ## @seealso{isvector, ismatrix}
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
23 ## @end deftypefn
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
24
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
25 ## Author: jwe
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
26
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
27 function retval = isscalar (x)
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
28
12604
132c89bb44e3 maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents: 12491
diff changeset
29 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5721
diff changeset
30 print_usage ();
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
31 endif
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
32
12604
132c89bb44e3 maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents: 12491
diff changeset
33 retval = numel (x) == 1;
132c89bb44e3 maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents: 12491
diff changeset
34
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
35 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
36
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
37
14039
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
38 %!assert (isscalar (1))
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
39 %!assert (isscalar ([1, 2]), false)
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
40 %!assert (isscalar ([]), false)
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
41 %!assert (isscalar ([1, 2; 3, 4]), false)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
42
14039
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
43 %!assert (isscalar ("t"))
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
44 %!assert (isscalar ("test"), false)
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
45 %!assert (isscalar (["test"; "ing"]), false)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
46
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
47 %!test
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
48 %! s.a = 1;
14039
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
49 %! assert (isscalar (s));
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
50
12491
981cd6796065 Use modern warning function rather than deprecated built-in variable to set warning state.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
51 %% Test input validation
14039
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
52 %!error isscalar ()
e98140f84ae0 test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents: 12604
diff changeset
53 %!error isscalar (1, 2)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
54