NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/matutil/identical.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function theResult = identical(varargin)
2
3 % identical -- Nan-safe "isequal".
4 %  identical(x, y, ...) returns TRUE if all the
5 %   arguments are identical in shape and value,
6 %   even with respect to NaNs.  No distinction
7 %   is made between the number-like classes.
8  
9 % Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO.
10 %  All Rights Reserved.
11 %   Disclosure without explicit written consent from the
12 %    copyright owner does not constitute publication.
13  
14 % Version of 05-Sep-2001 01:48:57.
15 % Updated    05-Sep-2001 02:32:14.
16
17 if nargout > 0, theResult = []; end
18 if nargin < 2, help(mfilename), return, end
19
20 % Check "isequal" first.
21
22 yes = isequal(varargin{:});
23 if yes
24         if nargout > 0
25                 theResult = yes;
26         else
27                 disp(yes)
28         end
29         return
30 end
31
32 % Not exactly equal.  Decompose the arguments,
33 %  checking for equality of the pieces.
34
35 x = varargin{1};
36
37 for k = 2:length(varargin)
38         y = varargin{k};
39         yes = isequal(x, y);
40         if ~yes
41                 switch class(x)
42                 case 'cell'
43                         if isequal(class(y), 'cell')
44                                 if isequal(size(x), size(y))
45                                         for i = 1:prod(size(x))
46                                                 yes = feval(mfilename, x{i}, y{i});
47                                                 if ~yes, break, end
48                                         end
49                                 end
50                         end
51                 case 'struct'
52                         if isequal(class(y), 'struct')
53                                 fx = fieldnames(x);
54                                 if isequal(fx, fieldnames(y))
55                                         for i = 1:length(fx)
56                                                 gx = getfield(x, fx{i});
57                                                 gy = getfield(y, fx{i});
58                                                 yes = feval(mfilename, gx, gy);
59                                                 if yes, break, end
60                                         end
61                                 end
62                         end
63                 case {'char', 'double', 'sparse', 'uint8', 'uint32'}
64                         nx = isnan(x);
65                         if isequal(size(x), size(y)) & any(nx(:))
66                                 ny = isnan(y);
67                                 if isequal(nx, ny)
68                                         yes = isequal(x(~nx), y(~ny));
69                                 end
70                         end
71                 otherwise
72                 end
73         end
74         if ~yes, break, end
75 end
76
77 if nargout > 0
78         theResult = yes;
79 else
80         disp(yes)
81 end
Note: See TracBrowser for help on using the browser.