Info

This question is closed. Reopen it to edit or answer.

How to get accurate normal and binomial distribution plots

1 view (last 30 days)
I am trying to get a graphical representation of my binomalpdf and normalpdf, however only get flat lines instead, and am not sure why. The code used is listed below.
%the main data set; it is the number of threads %run by my CPU at 3 percent load, collected every other %second for 100 seconds, resulting in 50 data points.
data = [1103, 1101, 1100, 1097, 1099, 1095, 1096, 1096, 1098, 1097, 1096, 1094, 1096, 1097, 1087, 1085, 1084, 1087, 1086, 1082, 1079, 1081, 1078, 1080, 1081, 1077, 1079, 1074, 1073, 1069, 1068, 1064, 1066, 1065, 1066, 1066, 1065, 1065, 1063, 1066, 1067, 1065, 1058, 1060, 1061, 1061, 1060, 1059, 1058, 1057];
%calculates the mean(mu), the mode(md), %the median,(mdn), the standard deviation(sigma), %and the range(rng).
mu = mean(data)
md = mode(data)
mdn = median(data)
sigma = std(data)
rng = range(data)
%closes any open windows and sets the screen size
close all;
scrsz = get(0,'ScreenSize');
%Data Histogram
hist(data,65);
annotation('textbox', [.35, .7, .35, .2]);
%makes them variables in the command window
m = 10;
n = 1;
Array = zeros(m,n);
assignin('base', 'm', m);
assignin('base', 'n', n);
assignin('base', 'Array', Array);
%figure normal distribution plot;
xx = [0:.1:49];
figure('Position',[200 scrsz(4)/2 scrsz(4)/2 scrsz(4)/2-100])
plot(xx,normpdf(data,mu,sigma));
title('Normal data');
xlabel('');
ylabel('Value pdf');
%figure binomial distribution plot;
P= .5;
K = 50;
dnormal=binopdf(data,K,P);
figure('Position',[300 scrsz(4)/2 scrsz(4)/2 scrsz(4)/2-100])
plot(data,dnormal,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... v b 'MarkerSize',10)
title('Binomial pdf data');
xlabel('data');
ylabel(['pdf for N = ',num2str(50),' and P = ',... num2str(P)]);
  2 Comments
Image Analyst
Image Analyst on 22 Sep 2013
I don't have range(). What does it do? (Please list below what toolbox it is in also.)
the cyclist
the cyclist on 22 Sep 2013
@Peter, I could not get your code to execute. The first plot() command gives and error due to the vectors being different sizes.
@Image Analyst, range() is in the Statistics Toolbox. range(data) is effectively max(data)-min(data) here.

Answers (0)

Community Treasure Hunt

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

Start Hunting!