%!demo
%! ## Plot the PDF of a Half-normal distribution, with parameters mu = 0
%! ## and sigma = 1, truncated at [0.5, 2] intervals. Generate 10000 random
%! ## samples from this truncated distribution and superimpose a histogram scaled
%! ## accordingly
%!
%! rand ("seed", 21);
%! data_all = abs (randn (20000, 1));
%! data = data_all(data_all >= 0.5 & data_all <= 2);
%! data = data(1:10000);
%!
%! pd = fitdist (data, "HalfNormal");
%! t = truncate (pd, 0.5, 2);
%!
%! ## Plot histogram and truncated PDF
%! plot (t)
%! hold on
%! hist (data, 50)
%! hold off
%! title ("Half-normal distribution (mu = 0, sigma = 1) truncated at [0.5, 2]")
%! legend ("Truncated PDF", "Histogram")
%!
%! ## This demonstrates truncating a Half-normal distribution to a specific
%! ## range and visualizing the resulting distribution with random samples.
