5178
|
1 ## Copyright (C) 2000 Paul Kienzle |
|
2 ## |
5181
|
3 ## This file is part of Octave. |
5178
|
4 ## |
5181
|
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. |
5178
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
5181
|
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. |
5178
|
19 |
5182
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} isequal (@var{x1}, @var{x2}, @dots{}, @var{xN}) |
|
22 ## Return true if all parts of @var{x1}, @var{x2}, @dots{}, @var{xN} are |
|
23 ## equal. |
|
24 ## @end deftypefn |
5178
|
25 |
5181
|
26 ## Author: Paul Kienzle |
|
27 ## Adapted-by: jwe |
|
28 |
|
29 function t = isequal (x, varargin) |
|
30 |
5393
|
31 if (nargin < 2) |
5181
|
32 usage ("isequal (x, y, ...)"); |
5178
|
33 endif |
|
34 |
5181
|
35 for arg = 1:length (varargin) |
5178
|
36 y = varargin{arg}; |
5181
|
37 if (isstruct (x)) |
5178
|
38 t = isstruct (y); |
|
39 for [v, k] = x |
5181
|
40 t = (t |
|
41 && struct_contains (y, k) |
|
42 && isequal (getfield (x, k), getfield (y, k))); |
5178
|
43 endfor |
5181
|
44 for [v, k] = y |
5178
|
45 t = t && struct_contains (x, k); |
|
46 endfor |
5181
|
47 elseif (islist (x)) |
5178
|
48 t = islist(y) && length(x) == length(y); |
5181
|
49 if (! t) |
|
50 return; |
|
51 endif |
|
52 for i = 1:length (x) |
5178
|
53 t = isequal (x{i}, y{i}); |
5181
|
54 if (! t) |
|
55 return; |
|
56 endif |
5178
|
57 endfor |
5181
|
58 elseif (any (size (x) != size (y))) |
5178
|
59 t = false; |
5181
|
60 elseif (iscell (x) || islist (x)) |
|
61 t = iscell (y) || islist (y); |
|
62 if (! t) |
|
63 return; |
|
64 endif |
|
65 x = x(:); |
|
66 y = y(:); |
|
67 for i = 1:length (x) |
5178
|
68 t = isequal (x{i}, y{i}); |
5181
|
69 if (! t) |
|
70 return; |
|
71 endif |
5178
|
72 endfor |
|
73 else |
5181
|
74 t = all (x(:) == y(:)); |
5178
|
75 endif |
5181
|
76 if (! t) |
|
77 return; |
|
78 endif |
5178
|
79 endfor |
5181
|
80 |
5178
|
81 endfunction |