Mercurial > hg > octave-lyh
annotate scripts/general/isvector.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 |
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} {} isvector (@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 vector. A vector is a 2-D array |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
22 ## where one of the dimensions is equal to 1. As a consequence a |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
23 ## 1x1 array, or scalar, is also a vector. |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
24 ## @seealso{isscalar, ismatrix, size, rows, columns, length} |
4026 | 25 ## @end deftypefn |
26 | |
27 ## Author: jwe | |
28 | |
29 function retval = isvector (x) | |
30 | |
12604
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
12491
diff
changeset
|
31 if (nargin != 1) |
6046 | 32 print_usage (); |
4026 | 33 endif |
34 | |
12604
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
12491
diff
changeset
|
35 sz = size (x); |
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
12491
diff
changeset
|
36 retval = (ndims (x) == 2 && (sz(1) == 1 || sz(2) == 1)); |
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
12491
diff
changeset
|
37 |
4026 | 38 endfunction |
7411 | 39 |
40 | |
14039
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
41 %!assert (isvector (1)) |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
42 %!assert (isvector ([1; 2; 3])) |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
43 %!assert (isvector ([]), false) |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
44 %!assert (isvector ([1, 2; 3, 4]), false) |
7411 | 45 |
14039
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
46 %!assert (isvector ("t")) |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
47 %!assert (isvector ("test")) |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
48 %!assert (isvector (["test"; "ing"]), false) |
7411 | 49 |
50 %!test | |
51 %! s.a = 1; | |
14039
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
52 %! assert (isvector (s)); |
7411 | 53 |
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
|
54 %% Test input validation |
14039
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
55 %!error isvector () |
e98140f84ae0
test: Rewrite %!tests to preserve warning state.
Rik <octave@nomad.inbox5.com>
parents:
12604
diff
changeset
|
56 %!error isvector ([1, 2], 2) |
7411 | 57 |