Mercurial > octave-nkf
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 |
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 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
4026 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4026 | 18 |
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 | 23 ## @end deftypefn |
24 | |
25 ## Author: jwe | |
26 | |
27 function retval = isscalar (x) | |
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 | 30 print_usage (); |
4026 | 31 endif |
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 | 35 endfunction |
7411 | 36 |
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 | 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 | 46 |
47 %!test | |
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 | 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 | 54 |