-
Notifications
You must be signed in to change notification settings - Fork 0
/
normTrim.m
29 lines (26 loc) · 951 Bytes
/
normTrim.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
function [transfdata] = normTrim(data,dim,trmamt, trimsype)
%this transforms the data to make it normal .. or least attempting !
% trimtype: 'remove' OR 'winsorize'
sz=size(data);
nodims=1:length(sz);
nontransdims=setdiff(nodims,dim);
data=permute(data,[dim, nontransdims]);
data=reshape(data,sz(dim),[]);
data=sort(data,1);
datasize_id=sum(~isnan(data),1);
databorder_id=[ceil(datasize_id*(trmamt/2)/100); floor(datasize_id*(100-(trmamt/2))/100)];
switch trimsype
case 'remove'
for i=1:size(data,2)
data(1:(databorder_id(1,i))-1,i)=NaN;
data(((databorder_id(2,i))+1):datasize_id,i)=NaN;
end
case 'winsorize'
for i=1:size(data,2)
data(1:(databorder_id(1,i))-1,i)=data(databorder_id(1,i),i);
data(((databorder_id(2,i))+1):datasize_id,i)=data(databorder_id(2,i),i);
end
end
recomdims([dim, nontransdims])=nodims;
transfdata=reshape(data,sz(recomdims));
end