-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcarrayMax.m
62 lines (39 loc) · 1.19 KB
/
mcarrayMax.m
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
function maxOut = mcarrayMax(d,maxtype)
%
% Max value across all mocap structs in an array.
% If the number of frames in the structs are different, the longer structs
% will be cut.
%
% maxOut = mcarrayMax(d)
% maxOut = mcarrayMax(d,maxtype)
%
% d: array of mocap structs
% maxtype: 'normal' (Default) choose max value across all data streams
% 'absmax' choose most extreme value (disregard sign)
%
% maxout: a single mocap struct
%
% By Kristian Nymoen, RITMO/University of Oslo, 2019
%
if nargin < 2
maxtype = 'normal';
end
dframes = min([d.nFrames]);
dmarkers = max([d.nMarkers]);
dl = length(d);
q = nan(dframes,dmarkers*3,dl);
for i = 1:dl
q(1:dframes,1:1:d(i).nMarkers*3,i) = d(i).data(1:dframes,:);
end
maxOut = d(1);
maxOut.nFrames = dframes;
maxOut.nMarkers = dmarkers;
maxOut.filename = 'arraymax';
if strcmpi(maxtype,'absmax')
[~,y] = nanmax(abs(q),[],3);
x= (1:dframes*dmarkers*3)' + (y(:)-1)*(dframes*dmarkers*3);
maxOut.data = reshape(q(x(:)),dframes,dmarkers*3);
else
maxOut.data = nanmax(q,[],3);
end
end