%!demo
%! ## Plot the PDF of a Nakagami distribution, with parameters mu = 1
%! ## and omega = 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 = nakarnd (1, 1, 20000, 1);
%! data = data_all(data_all >= 0.5 & data_all <= 2);
%! data = data(1:10000);
%!
%! pd = fitdist (data, "Nakagami");
%! t = truncate (pd, 0.5, 2);
%! [counts, centers] = hist (data, 50);
%! bin_width = centers(2) - centers(1);
%! bar (centers, counts / (sum (counts) * bin_width), 1);
%! hold on;
%!
%! ## Plot histogram and truncated PDF
%! x = linspace (0.5, 5, 500);
%! y = pdf (t, x);
%! plot (x, y, "r", "linewidth", 2);
%! title ("Nakagami distribution (mu = 1, omega = 1) truncated at [0.5, 2]")
%! legend ("Truncated PDF", "Histogram")
%!
%! ## This demonstrates truncating a Nakagami distribution to a specific range
%! ## and visualizing the resulting distribution with random samples.
