Mercurial > hg > octave-nkf
annotate scripts/general/isvector.m @ 11431:0d9640d755b1
Improve docstrings for all isXXX functions.
Use 'return true' rather than 'return 1'.
Improve the cross-referencing through seealso links.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 31 Dec 2010 13:20:44 -0800 |
parents | eb63fbe60fab |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 1997, 2002, 2004, 2005, 2006, 2007, 2008 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 | |
31 retval = 0; | |
32 | |
33 if (nargin == 1) | |
5459 | 34 sz = size (x); |
5721 | 35 retval = (ndims (x) == 2 && (sz(1) == 1 || sz(2) == 1)); |
4026 | 36 else |
6046 | 37 print_usage (); |
4026 | 38 endif |
39 | |
40 endfunction | |
7411 | 41 |
42 %!assert(isvector (1)); | |
43 | |
44 %!assert(isvector ([1; 2; 3])); | |
45 | |
46 %!assert(!(isvector ([]))); | |
47 | |
48 %!assert(!(isvector ([1, 2; 3, 4]))); | |
49 | |
50 %!test | |
51 %! warn_str_to_num = 0; | |
52 %! assert((isvector ("t"))); | |
53 | |
54 %!test | |
55 %! warn_str_to_num = 0; | |
56 %! assert((isvector ("test"))); | |
57 | |
58 %!assert(!(isvector (["test"; "ing"]))); | |
59 | |
60 %!test | |
61 %! s.a = 1; | |
62 %! assert((isvector (s))); | |
63 | |
64 %!error isvector (); | |
65 | |
66 %!error isvector ([1, 2], 2); | |
67 |