normal distribution graph/histogram/plot

24 views (last 30 days)
Hello, I am in the process of doing the task and I have encountered a problem with drawing a histogram / graph.
below is the script that will perform the task of n rolls of two cubic dice and calculate the sum of the spots rolled:
count = 0;
for i=1:10
throws1 = randi(6, 1);
throws2 = randi(6, 1);
sumThrow = throws1 + throws2;
fprintf('suma : %d\n', sumThrow)
and a function that calculates the expected value and standard deviation:
function [x,y] = external_pdf(mu,sigma)
% [x,y] = external_pdf(mu, sigma)
% mu is expected value
% sigma is standard deviation
% [x,y] = external_pdf(7,2.42)
% plot(x,y)
x = (mu-(3*sigma)):.1:(mu+(3*sigma))
y = 1/(sigma*sqrt(2*pi))*exp(-(x-mu).^2/(2*sigma^2))
I tries to draw a normalized histogram and plot a normal distribution graph with the parameters N (7, 2.41), using the command: normfit (7,2.41) - it is supposed to calculate the normal distribution, but when I try to draw it with the histogram command, I get the following drawing, and I'm rather doing something wrong.
below is the content of the task it performs:
Write a script that will do a task n rolls of two cubes and calculate
the total number of pips rolled. Find the expected value and standard deviation. Draw a number of
a calculated histogram and plot a normal distribution plot with parameters N (7, 2.41).
Use the randi, normfit, hist, trapz and plot functions.

Accepted Answer

Cris LaPierre
Cris LaPierre on 20 Mar 2021
Edited: Cris LaPierre on 20 Mar 2021
Can I assume that this is how you created your histogram?
N = normfit(7,2.41)
N = 7
It might be worth reviewing what a histogram is. The y axis is a count of the number of data points that fall within each bin. The x axis indicates the bin edges.
Here, N is a single value, 7. So your histogram has a single bin centered at 7, with a height of 1 because 1 value falls within the bin for 7.
If you want a histogram to show a normal distribution, you will need lots of data points, and several bins. For example
nums = randn(1000,1); % 1000 normally distributed random numbers

More Answers (0)


Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!