File: GroupStructArrayByFields.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (32 lines) | stat: -rw-r--r-- 826 bytes parent folder | download
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
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.
%
% 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