Hi,
When you multiply the PDF by N*50, you're assuming each bin of the histogram represents an equal division of the probability, which is not accurate. The correct scaling factor should consider the bin width of the histogram, not just the number of bins, to ensure the areas under the histogram and the Gaussian curve are comparable.
Here's how you can modify the scaling factor to correctly plot the histograms and their corresponding Gaussian distributions:
binWidth1 = (max(R1) - min(R1)) / numBins;
binWidth2 = (max(R2) - min(R2)) / numBins;
% Generate points for the Gaussian PDF and scale correctly
X = linspace(min([R1;R2]), max([R1;R2]), 1000); % Adjusted range for both R1 and R2
Y1 = normpdf(X, mean(R1), std(R1)) * N * binWidth1; % Correct scaling
Y2 = normpdf(X, mean(R2), std(R2)) * N * binWidth2;
Alternatively, you could normalize the histogram so that the area (or integral) under the histogram equals 1. You can do this by using the "histogram" function for plotting histograms(instead of "hist"), with a name-value pair of "Normalization" and "pdf":
histogram(R1, numBins, 'Normalization', 'pdf');
Hope this helps!