y=nt_fixsign(x) - flip signs to maximize inter-component correlation
0001 function x=nt_fixsign(x) 0002 %y=nt_fixsign(x) - flip signs to maximize inter-component correlation 0003 0004 if ndims(x)<3; 0005 y=nt_pca(x); 0006 y=y(:,1)'*x; % correlation with PC 0007 x=x*sign(diag(y)); 0008 else 0009 [m,n,o]=size(x); 0010 if 0 0011 % can't remember the logic of this... 0012 for k=1:n 0013 x(:,k,:)=reshape(nt_fixsign(squeeze(x(:,k,:))), [m,1,o]); 0014 end 0015 else 0016 x=nt_fold(nt_fixsign(nt_unfold(x)),m); 0017 end 0018 end 0019 0020 % flip whold matrix so highest peak is positive 0021 if abs(max(x(:)))<abs(min(x(:))) 0022 x=-x; 0023 end