/usr/share/psychtoolbox-3/PsychOneliners/GroupStructArrayByFields.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
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 | function theGroupedArray = GroupStructArrayByFields(theStructArray,theFields)
% theGroupedArray = GroupStructArrayByFields(theStructArray,theFields)
%
% Group together the members of a struct array that share the same values
% in the passed fields.
%
% This is useful for sorting/grouping elements in a struct array on
% parameters that signify membership of trials to a particular condition.
%
% 7/21/03 dhb Wrote it.
theGroupedArray = {};
nStructs = length(theStructArray);
% The first passed structure is equal to itself
nGroups = 1;
theGroupedArray{1} = theStructArray(1);
% Put structures into groups, creating new ones as necessary.
for i = 2:nStructs
didIt = 0;
for j = 1:nGroups
if AreStructsEqualOnFields(theStructArray(i),theGroupedArray{j}(1),theFields)
theGroupedArray{j} = [theGroupedArray{j} theStructArray(i)];
didIt = 1;
break;
end
end
if (~didIt)
nGroups = nGroups+1;
theGroupedArray{nGroups} = theStructArray(i);
end
end
|