% function rri_xcor
%  syntax:  outmat=rri_xcor(design,datamat)
%  Computes crosscorrelation of two matrices
%  Written by ARM 12-15-94


function[outmat]=rri_xcor(design,datamat)

[r c]=size(datamat);

avg=mean(datamat);
stdev=std(datamat);
checknan=find(stdev==0);

if (isempty(checknan)==0)
     for i=1:r
     datamat(i,checknan)=0;
     end  %for

     avg(checknan)=0;
     stdev(checknan)=1;
end %if

 for i=1:r
  datamat(i,:)=(datamat(i,:)-avg)./stdev;
 end

[dr dc]=size(design);

davg=mean(design);
dstdev=std(design);

checknan=find(dstdev==0);
if (isempty(checknan)==0)
     for i=1:r
     design(i,checknan)=0;
     end  %for

     davg(checknan)=0;
     dstdev(checknan)=1;
end %if

for i=1:dr
 design(i,:)=(design(i,:)-davg)./dstdev;
end

xprod=design'*datamat;
outmat=xprod./(r-1);

