comparison scripts/general/isequal.m @ 5181:41cd70503c72

[project @ 2005-03-03 05:49:55 by jwe]
author jwe
date Thu, 03 Mar 2005 05:49:55 +0000
parents 6758c11b5b99
children 5b361aa47dff
comparison
equal deleted inserted replaced
5180:e7438487c857 5181:41cd70503c72
1 ## Copyright (C) 2000 Paul Kienzle 1 ## Copyright (C) 2000 Paul Kienzle
2 ## 2 ##
3 ## This program is free software; you can redistribute it and/or modify 3 ## This file is part of Octave.
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ## 4 ##
8 ## This program is distributed in the hope that it will be useful, 5 ## Octave is free software; you can redistribute it and/or modify it
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 6 ## under the terms of the GNU General Public License as published by
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7 ## the Free Software Foundation; either version 2, or (at your option)
11 ## GNU General Public License for more details. 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.
12 ## 14 ##
13 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software 16 ## along with Octave; see the file COPYING. If not, write to the Free
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
18 ## 02111-1307, USA.
16 19
17 ## isequal(x1, x2, ...) 20 ## isequal(x1, x2, ...)
18 ## true if all parts of x1, x2, ... are equal 21 ## true if all parts of x1, x2, ... are equal
19 22
20 function t = isequal(x,varargin) 23 ## Author: Paul Kienzle
21 if nargin != 2 24 ## Adapted-by: jwe
22 usage("isequal(x,y,...)"); 25
26 function t = isequal (x, varargin)
27
28 if (nargin != 2)
29 usage ("isequal (x, y, ...)");
23 endif 30 endif
24 31
25 for arg = 1:length(varargin) 32 for arg = 1:length (varargin)
26 y = varargin{arg}; 33 y = varargin{arg};
27 if isstruct(x) 34 if (isstruct (x))
28 t = isstruct (y); 35 t = isstruct (y);
29 for [v, k] = x 36 for [v, k] = x
30 t = t && struct_contains (y, k) && isequal (getfield(x,k), getfield(y,k)); 37 t = (t
38 && struct_contains (y, k)
39 && isequal (getfield (x, k), getfield (y, k)));
31 endfor 40 endfor
32 for [v,k] = y 41 for [v, k] = y
33 t = t && struct_contains (x, k); 42 t = t && struct_contains (x, k);
34 endfor 43 endfor
35 elseif islist(x) 44 elseif (islist (x))
36 t = islist(y) && length(x) == length(y); 45 t = islist(y) && length(x) == length(y);
37 if !t, return; endif 46 if (! t)
38 for i = 1:length(x) 47 return;
48 endif
49 for i = 1:length (x)
39 t = isequal (x{i}, y{i}); 50 t = isequal (x{i}, y{i});
40 if !t, return; endif 51 if (! t)
52 return;
53 endif
41 endfor 54 endfor
42 elseif any (size (x) != size (y)) 55 elseif (any (size (x) != size (y)))
43 t = false; 56 t = false;
44 elseif iscell(x) || islist(x) 57 elseif (iscell (x) || islist (x))
45 t = iscell (y) || islist(y); 58 t = iscell (y) || islist (y);
46 if !t, return; endif 59 if (! t)
47 x = x (:); 60 return;
48 y = y (:); 61 endif
49 for i = 1:length(x) 62 x = x(:);
63 y = y(:);
64 for i = 1:length (x)
50 t = isequal (x{i}, y{i}); 65 t = isequal (x{i}, y{i});
51 if !t, return; endif 66 if (! t)
67 return;
68 endif
52 endfor 69 endfor
53 else 70 else
54 t = all (x (:) == y (:)); 71 t = all (x(:) == y(:));
55 endif 72 endif
56 if !t, return; endif 73 if (! t)
74 return;
75 endif
57 endfor 76 endfor
77
58 endfunction 78 endfunction