function Xnew = outliers2nan( Xraw )

q1 = quantile(Xraw, 0.25);
q3 = quantile(Xraw, 0.75);
lolim = q1 - 1.5*(q3-q1);
uplim = q3 + 1.5*(q3-q1);

Xnew = Xraw;
Xnew(Xraw>uplim) = nan;
Xnew(Xraw<lolim) = nan;

while sum(isnan(Xnew)) ~= sum(isnan(Xraw))
    Xraw = Xnew;
    Xnew = outliers2nan( Xraw );
end

end

