2847
|
1 ## Copyright (C) 1996, 1997 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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
2823
|
19 |
3449
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} logical (@var{arg}) |
|
22 ## Convert @var{arg} to a logical value. For example, |
2823
|
23 ## |
3449
|
24 ## @example |
|
25 ## logical ([-1, 0, 1]) |
|
26 ## @end example |
2823
|
27 ## |
3449
|
28 ## @noindent |
2823
|
29 ## is equivalent to |
|
30 ## |
3449
|
31 ## @example |
|
32 ## [-1, 0, 1] != 0 |
|
33 ## @end example |
|
34 ## @end deftypefn |
2823
|
35 |
|
36 ## Author: jwe |
|
37 |
|
38 function y = logical (x) |
|
39 |
|
40 if (nargin == 1) |
3674
|
41 if (islogical (x) || isempty (x)) |
|
42 y = x; |
|
43 elseif (isnumeric (x)) |
3225
|
44 y = x != 0; |
|
45 else |
3674
|
46 error ("logical not defined for type `%s'", typeinfo (x)); |
3225
|
47 endif |
2823
|
48 else |
|
49 usage ("logical (x)"); |
|
50 endif |
|
51 |
|
52 endfunction |