MATLAB: How to truncate a normally distributed random variable

normal distributiontruncation

I have a random variable 'y' that follows the normal distribution. For example:
x = -4:0.1:4;
y = normpdf(x);
I need to create another vector consisting of elements of 'y' truncated at a certain point, how do I do that?

Best Answer

xtl = 2.0; % left point of trunction
xtr = Inf; % right point of truncation
x = -4:0.1:4;
y = normpdf(x);
yt = normpdf(x)/(normcdf(xtr)-normcdf(xtl)).*(x>=xtl).*(x<=xtr);
Best wishes
Torsten.