0001 function [iBest,y,topo]=nt_back(x,z,layout)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if nargin==0; test_code; return; end
0016
0017 if nargin<2; error('!'); end
0018 if nargin<3||isempty(layout); layout=[]; end
0019 if ndims(x)~=ndims(z); error('!'); end
0020
0021 if ndims(x)==3
0022
0023 [m,n,o]=size(x);
0024 x=nt_unfold(x);
0025 z=nt_unfold(z);
0026 if nargout~=0
0027 [iBest,y,topo]=nt_back(x,z,layout);
0028 y=nt_fold(y,m);
0029 else
0030 nt_back(x,z,layout);
0031 end
0032 return;
0033 end
0034
0035
0036
0037 z=nt_normcol(z);
0038 topo=nt_xcov(z,x)/size(x,1);
0039
0040
0041 [~,iBest]=max(abs(topo)');
0042
0043
0044 for iComp=1:size(z,2)
0045 y(:,iComp)=z(:,iComp)*topo(iComp,iBest(iComp));
0046 end
0047
0048
0049 for iComp=1:size(z,2)
0050 topo(iComp,:)=topo(iComp,:)*sign(mean(z(:,iComp).*y(:,iComp)));
0051 end
0052
0053
0054
0055
0056 if nargout==0
0057 disp('nt_back: no output requested, plot back matrices');
0058
0059 J=floor(sqrt(size(z,2)));
0060 K=ceil(size(z,2)/J);
0061
0062 figure(101); clf;
0063 nt_banner('best channel for each component','fontsize',16)
0064 for iComp=1:size(z,2)
0065 subplot(J,K,iComp);
0066 plot(x(:,iBest(iComp)), ':k'); hold on
0067 plot(y(:,iComp), 'b');
0068 title(['c',num2str(iComp), ', ch', num2str(iBest)]);
0069 end
0070
0071 if ~isempty(layout)
0072 figure(102); clf
0073 nt_banner('RMS per channel','fontsize',16)
0074 for iComp=1:size(z,2)
0075 subplot(J,K,iComp);
0076 nt_topoplot(layout, topo(iComp,:)); colorbar
0077 title(iComp);
0078 end
0079 end
0080
0081 clear iBest y topo
0082 end
0083
0084
0085
0086 end
0087
0088
0089
0090
0091
0092 function test_code
0093 disp('nt_back test code');
0094 disp('3D random matrix, apply nt_dss1, give to nt_back()');
0095
0096 x=randn(1000,10,10);
0097 [todss]=nt_dss1(x);
0098 nt_back(x,todss)
0099 end