function y = maskmean(x,mask,dim)

if ~(isequal(size(x), size(mask)) || (isvector(x) && isvector(mask) && numel(x) == numel(mask)))
    Disp('size of x and mask do not match...'); 
else
    x(~mask) = nan;
    y = mean(x,dim,'omitnan');
    %y(isnan(y)) = 0;
end
