function [res]=correlnan(var1,var2)

tmp1=var1;
tmp2=var2;
validdata1 = ~isnan(tmp1);
validdata2 = ~isnan(tmp2);
validdataBoth = validdata1 & validdata2;
keep1 = tmp1(validdataBoth) ;
keep2 = tmp2(validdataBoth) ;
res=corr(keep1(:), keep2(:),'type','pearson');

end