Using the below m file coding as a starting point, write a MATLAB script which generates N
samples from a Rayleigh distribution, and compares the sample histogram with the
Rayleigh density function. can anybody tell how to write from this starting?
% GAUSSIANHIST

clear

%%%%% Initialisation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mu = 0; % mean (mu)
sig = 2; % standard deviation (sigma)
N = 1e5; % number of samples

%%%%% Sample from Gaussian distribution %%%%%%%%%%%%%%%%%%%

z = mu + sig*randn(1,N);

%%%%% Plot sample histogram, scaling vertical axis %%%%%%%%
%%%%% to ensure area under histogram is 1 %%%%%%%%%%%%%%%%%

dx = 0.5;
x = mu-5*sig:dx:mu+5*sig; % mean, and 5 standard
% deviations either side
H = hist(z,x);
area = sum(H*dx);
H = H/area;
bar(x,H)
xlim([-5*sig,5*sig])

%%%%% Overlay Gaussian density function %%%%%%%%%%%%%%%%%%%

hold on
f = exp(-(x-mu).^2/(2*sig^2))/sqrt(2*pi*sig^2);
plot(x,f,'r','LineWidth',3)
hold off