7017
|
1 ## Copyright (C) 1996, 1997, 1998, 2000, 2005, 2006, 2007 John W. Eaton |
2823
|
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. |
2823
|
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/>. |
2823
|
18 |
3449
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} logical (@var{arg}) |
|
21 ## Convert @var{arg} to a logical value. For example, |
2823
|
22 ## |
3449
|
23 ## @example |
|
24 ## logical ([-1, 0, 1]) |
|
25 ## @end example |
2823
|
26 ## |
3449
|
27 ## @noindent |
2823
|
28 ## is equivalent to |
|
29 ## |
3449
|
30 ## @example |
|
31 ## [-1, 0, 1] != 0 |
|
32 ## @end example |
|
33 ## @end deftypefn |
2823
|
34 |
|
35 ## Author: jwe |
|
36 |
|
37 function y = logical (x) |
|
38 |
|
39 if (nargin == 1) |
3674
|
40 if (islogical (x) || isempty (x)) |
|
41 y = x; |
|
42 elseif (isnumeric (x)) |
3225
|
43 y = x != 0; |
|
44 else |
3674
|
45 error ("logical not defined for type `%s'", typeinfo (x)); |
3225
|
46 endif |
2823
|
47 else |
6046
|
48 print_usage (); |
2823
|
49 endif |
|
50 |
|
51 endfunction |