1 function [iseq, diffs, add1, add2] = structcmp(s1,s2,ignorelist)
2 %
function [iseq, diffs, add1, add2] = structcmp(s1,s2,ignorelist);
4 % compare two structures s1 and s2 and ignoring fields given in the
5 % cell-array of fielnames ignorelist.
6 % iseq = 1
if the structures are identical except ignorelist
7 % diffs is a cell array of the fieldnames persistent in both
8 % structs but differing, add1 are the fields existing in s1 but
9 % not in s2, add2 is a cell array of fieldnames existing in
11 %
function handles are ignored automatically, as they cannot be compared
13 % Bernard Haasdonk 23.5.2007
17 if (nargin<3) || isempty(ignorelist)
22 f1 = setdiff(f1, ignorelist);
24 f2 = setdiff(f2, ignorelist);
25 add1 = setdiff(f1,f2);
26 add2 = setdiff(f2,f1);
27 fi = intersect(f1,f2);
30 if isa(s1.(fi{i}),
'function_handle')
31 if ~isequal(func2str(s1.(fi{i})), func2str(s2.(fi{i})))
32 diffs = [ diffs; {fi(i)}];
34 elseif iscell(s1.(fi{i})) ...
35 && all(cellfun(@(x) isa(x,
'function_handle'), s1.(fi{i})))
36 strings1 = cellfun(@func2str, s1.(f1{i}),
'UniformOutput',
false);
37 strings2 = cellfun(@func2str, s1.(f1{i}),
'UniformOutput',
false);
38 if ~isequal(strings1, strings2)
39 diffs = [ diffs; {fi(i)} ];
41 elseif ~isequal(s1.(fi{i}),s2.(fi{i}))
42 diffs = [diffs; {fi(i)}];
47 if ~isempty(diffs) || ...