7017
|
1 ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, 2007 |
|
2 ## Kurt Hornik |
3426
|
3 ## |
3922
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3426
|
10 ## |
3922
|
11 ## Octave is distributed in the hope that it will be useful, but |
2538
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
14 ## General Public License for more details. |
|
15 ## |
2538
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
2538
|
19 |
3321
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Mapping Function} {} xor (@var{x}, @var{y}) |
|
22 ## Return the `exclusive or' of the entries of @var{x} and @var{y}. |
|
23 ## For boolean expressions @var{x} and @var{y}, |
|
24 ## @code{xor (@var{x}, @var{y})} is true if and only if @var{x} or @var{y} |
|
25 ## is true, but not if both @var{x} and @var{y} are true. |
|
26 ## @end deftypefn |
2538
|
27 |
5428
|
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2538
|
29 ## Created: 16 September 1994 |
|
30 ## Adapted-By: jwe |
|
31 |
|
32 function z = xor (x, y) |
|
33 |
2621
|
34 if (nargin == 2) |
6157
|
35 if (isscalar (x) || isscalar (y) || size_equal (x, y)) |
2870
|
36 z = logical ((x | y) - (x & y)); |
2621
|
37 else |
|
38 error ("xor: x and y must be of common size or scalars"); |
|
39 endif |
|
40 else |
6046
|
41 print_usage (); |
2538
|
42 endif |
|
43 |
|
44 endfunction |
7385
|
45 |
|
46 %!assert((xor ([1, 1, 0, 0], [0, 1, 0, 1]) == [1, 0, 0, 1] |
|
47 %! && xor ([i, i, 0, 0], [1, 0, 1, 0]) == [0, 1, 1, 0])); |
|
48 |
|
49 %!assert(all (all (xor (eye (2), fliplr (eye (2))) == ones (2)))); |
|
50 |
|
51 %!error xor (); |
|
52 |
|
53 %!error xor (1, 2, 3); |
|
54 |