0001 function [fs1, fs2, er] = comp_struct_quiet(s1,s2,n1,n2,p,tol)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if nargin < 1; help comp_struct_quiet; error('I / O error'); end
0029 if nargin < 2; s2 = s1; end
0030 if nargin < 3; n1 = 's1'; end
0031 if nargin < 4; n2 = 's2'; end
0032 if nargin < 5; p = 0; elseif p ~= 1 && p ~= 0; p = 0; end
0033 if nargin < 6; tol = 1e-6; end
0034
0035
0036 fs1 = {}; fs2 = {}; er = {};
0037
0038
0039 if isstruct(s1) && isstruct(s2)
0040
0041 fn1 = fieldnames(s1);
0042 fn2 = fieldnames(s2);
0043
0044 pnt1 = zeros(1,length(fn1));
0045 for ii = 1:length(fn1)
0046 for jj = 1:length(fn2)
0047 if strcmp(fn1(ii),fn2(jj)); pnt1(ii) = jj; end
0048 end
0049 end
0050 pnt2 = zeros(1,length(fn2));
0051 for ii = 1:length(fn2)
0052 for jj = 1:length(fn1)
0053 if strcmp(fn2(ii),fn1(jj)); pnt2(ii) = jj; end
0054 end
0055 end
0056
0057 for ii = find(~pnt1)
0058 fs1 = [fs1; {[char(n1) '.' char(fn1(ii))]}];
0059 fs2 = [fs2; {''}]; er = [er; {'Un-matched'}];
0060 end
0061 for ii = find(~pnt2)
0062 fs2 = [fs2; {[char(n2) '.' char(fn2(ii))]}];
0063 fs1 = [fs1; {''}]; er = [er; {'Un-matched'}];
0064 end
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 pnt1i = find(pnt1); pnt2i = find(pnt2);
0080 for ii=1:numel(pnt1i)
0081
0082 for jj = 1:size(s1,2)
0083
0084 if size(s1,2) == 1
0085 n1p = [n1 '.' char(fn1(pnt1i(ii)))];
0086 n2p = [n2 '.' char(fn2(pnt2i(ii)))];
0087 else
0088 n1p = [n1 '(' num2str(jj) ').' char(fn1(ii))]; ...
0089 n2p = [n2 '(' num2str(jj) ').' char(fn2(pnt2(ii)))];
0090 end
0091 [fss1 fss2 err] = comp_struct_quiet(getfield(s1(jj),char(fn1(pnt1i(ii)))), ...
0092 getfield(s2(jj),char(fn2(pnt2i(ii)))),n1p,n2p,p);
0093 if ~iscell(err); err = cellstr(err); end
0094 fs1 = [fs1; fss1]; fs2 = [fs2; fss2]; er = [er; err];
0095 end
0096 end
0097 elseif isstruct(s1) ~= isstruct(s2)
0098
0099 disp(sprintf('%s %s Type mismatch - NOT equal',n1,n2));
0100 fs1 = cell(0,1); fs2 = fs1;
0101 if p; disp('Paused .....'); pause; end
0102 elseif isa(s1,'sym') && isa(s2,'sym')
0103
0104
0105 [ss1 r] = simple(s1); [ss2 r] = simple(s2);
0106 t = isequal(simplify(ss1),simplify(ss2));
0107 if ~t
0108
0109
0110 f1 = findsym(ss1); f2 = findsym(ss2);
0111 w = warning;
0112 if isequal(f1,f2)
0113
0114 temp = [1 findstr(f1,' ') + 1]; tres = NaN * zeros(1,30);
0115 for jj = 1:1e3
0116 ss1e = ss1; ss2e = ss2;
0117 for ii = 1:length(temp);
0118 tv = (real(rand^rand)) / (real(rand^rand));
0119 ss1e = subs(ss1e,f1(temp(ii)),tv);
0120 ss2e = subs(ss2e,f2(temp(ii)),tv);
0121 end
0122
0123 if isnan(ss1e) || isnan(ss2e)
0124 tres(jj) = 1;
0125 elseif (double(ss1e) - double(ss2e)) < tol
0126 tres(jj) = 1;
0127 end
0128 end
0129
0130 if sum(tres) == length(tres)
0131
0132 t = 1;
0133 end
0134 else
0135
0136 end
0137 warning(w)
0138 end
0139 if t
0140
0141 else
0142 disp(sprintf('%s %s do NOT match',n1,n2))
0143 fs1 = n1; fs2 = n2; er = 'Symbolic disagreement';
0144 end
0145 else
0146
0147 if isequal(s1,s2);
0148
0149 else
0150
0151
0152 if strcmp(num2str(size(s1)),num2str(size(s2)));
0153
0154 if ischar(s1) || iscell(s1) || ...
0155 (max(max(max(abs(s1 - s2)))) > tol * (max(max(max([s1 s2]))) ...
0156 - min(min(min([s1 s2])))))
0157
0158 disp(sprintf('%s %s do NOT match',n1,n2))
0159 fs1 = [fs1; {n1}]; fs2 = [fs2; {n2}]; er = [er; {'?'}];
0160 if ischar(s1)
0161 er1 = sprintf('%s is char - %s',n1,char(s1)); disp(er1);
0162 end
0163 if ischar(s2)
0164 er2 = sprintf('%s is char - %s',n2,char(s2)); disp(er2);
0165 end
0166 if exist('er1','var') && exist('er2','var')
0167 er = [er; {[er1 ' ---> ' er2]}];
0168 end
0169 if ~ischar(s1) && ~iscell(s1);
0170 er = sprintf('Max error (%%) = %g%%', ...
0171 max(max(max(abs(s1 - s2)))) / ...
0172 (max(max(max([s1 s2]))) - min(min(min([s1 s2])))));
0173 disp(er);
0174 end
0175 if p; disp('Paused .....'); pause; end
0176 else
0177
0178
0179 end
0180 else
0181
0182 disp(sprintf('%s %s do NOT match - DIFFERENT SIZES',n1,n2))
0183 fs1 = [fs1; {n1}]; fs2 = [fs2; {n2}]; er = [er; {'String size error'}];
0184 if p; disp('Paused .....'); pause; end
0185 end
0186 end
0187
0188 end
0189
0190
0191 if 1
0192 if ~isempty(fs1)
0193 for ii = 1:length(fs1)
0194 if strcmp(n1,fs1(ii))
0195 disp(sprintf('First Structure non-matched fields: %s',[n1]))
0196 end
0197 if p; disp('Paused .....'); pause; end
0198 end
0199 end
0200 if ~isempty(fs2)
0201 for ii = 1:length(fs2)
0202 if strcmp(n2,fs2(ii))
0203 disp(sprintf('Second Structure non-matched fields: %s',[n2]))
0204 end
0205 if p; disp('Paused .....'); pause; end
0206 end
0207 end
0208 end