/usr/share/psychtoolbox-3/PsychOneliners/AreStructsEqualOnFields.m is in psychtoolbox-3-common 3.0.9+svn2579.dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | function areEqual = AreStructsEqualOnFields(struct1,struct2,theFields)
% areEqual = AreStructsEqualOnFields(struct1,struct2,theFields)
%
% Returns 1 if two structs share the same value on each of the passed
% fields, 0 otherwise. Only checks numeric and string fields.
% For fields that are cell or struct, it does check that they are
% of same type, but doesn't descend and check the values.
%
% 5/1/05 dhb, jmk Handle cell and struct fields, a little bit.
nFields = length(theFields);
areEqual = 0;
% Loop over fields. Return on any indicator of non-equality.
% If we make it out the bottom, then set returne alue to 1,.
for i = 1:nFields
% If either struct is missing the passed field, we say not equal.
if (~isfield(struct1,theFields{i}) | ~isfield(struct2,theFields{i}))
return;
end
% Snag the fields
field1 = getfield(struct1,theFields{i});
field2 = getfield(struct2,theFields{i});
% If both fields are cell arrays, then we don't complain but
% we don't check either.
if (iscell(field1) & iscell(field2))
% If both fields are structs, then we don't complain or check.
elseif (isstruct(field1) & isstruct(field2))
else
% If either field is a cell array here, then one is and the
% otheri isn't, so the structs are not equal
if (iscell(field1) | iscell(field2))
return;
end
% If either field is a struct here, then one is and the other
% isn't, so the structs are not equal.
if (isstruct(field1) | isstruct(field2))
return;
end
% OK. Now we're down to numeric and string types.
% If fields aren't same type, forget it.
if (ischar(field1) & ~ischar(field2))
return;
end
if (ischar(field2) & ~ischar(field1))
return;
end
% They are the same type so check as appropriate.
if (ischar(field1))
if (~streq(field1,field2))
return;
end
else
if (any(field1 ~= field2))
return;
end
end
end
end
% If we arrive here, they are equal
areEqual = 1;
|