Mercurial > hg > octave-max
annotate scripts/general/isvector.m @ 12993:dfab2a8ca545 stable
doc: update sscanf doc string to match current behavior
* file-io.cc (Fsscanf): Document POS output.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 24 Aug 2011 11:20:26 -0400 |
parents | 981cd6796065 |
children | 132c89bb44e3 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1996-2011 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 %!assert(isvector ([1; 2; 3])); | |
44 %!assert(!(isvector ([]))); | |
45 %!assert(!(isvector ([1, 2; 3, 4]))); | |
46 | |
47 %!test | |
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
|
48 %! warning ("off", "Octave:str-to-num"); |
7411 | 49 %! assert((isvector ("t"))); |
50 | |
51 %!test | |
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
|
52 %! warning ("off", "Octave:str-to-num"); |
7411 | 53 %! assert((isvector ("test"))); |
54 | |
55 %!assert(!(isvector (["test"; "ing"]))); | |
56 | |
57 %!test | |
58 %! s.a = 1; | |
59 %! assert((isvector (s))); | |
60 | |
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
|
61 %% Test input validation |
7411 | 62 %!error isvector (); |
63 %!error isvector ([1, 2], 2); | |
64 |