function d=cohensD(sample1, sample2)

% Calculate Cohen's D effect size.
% Inputs: sample 1, sample 2

% Formula: (Mean1-Mean2)/SD pooled
% SD pooled = sqrt((SD1^2 + SD2^2)/2)

SDpooled=sqrt((nanstd(sample1)^2 + nanstd(sample2)^2)/2);
d=(nanmean(sample1)-nanmean(sample2))/SDpooled;