function out=vofvMadtTest(data1,data2,nreps)
out=zeros(nreps,1);

data1(isnan(data1))=[];
data2(isnan(data2))=[];

n1=length(data1);
n2=length(data2);

allData=[data1;data2];

nAll=n1+n2;

tic; h=waitbar(0);

for i=1:nreps
    
   which1=ceil(rand(n1,1)*nAll);
   which2=ceil(rand(n2,1)*nAll);
   data1Temp=allData(which1);
   data2Temp=allData(which2);
   out(i)=mad(data1Temp)-mad(data2Temp);

     if mod(i,100)==0
        tnow=toc; h=waitbar(i/nreps,h,['estimated time remaining: ' num2str((nreps-i)/nreps*(tnow/(i/nreps)))]);
    end
   
end
    
close(h);
disp(['p= ' num2str(sum(abs(out)>abs(mad(data1)-mad(data2)))/nreps)]);