Why is my code skipping numbers?

I'm trying to generate a 130×130 random field by drawing it from Gaussian distribution with standard deviation of 50 and expectation of 128. The Histogram of my data is showing skips in the numbers it generates, why is it doing this?
rng default
stdev = 50;
expectation = 128;
X = stdev.*randn(130) + expectation;
stats = [mean2(X) std2(X) var(X(:))];
fprintf('mean %f ... stardard dev %f ... variance %f\n',stats(1), stats(2), stats(3))
figure;
hist(X);
Thanks for any insights

Answers (1)

Stephen23
Stephen23 on 29 Mar 2017
Edited: Stephen23 on 29 Mar 2017
Your code is not skipping any numbers at all. The hist documentation clearly states that "If the input is a multi-column array, hist creates histograms for each column of x and overlays them onto a single plot."
Your data contains 130 columns, and therefore MATLAB (doing exactly what the documentation states) creates one plot with 130 histograms on it, each with ten bins:
>> size(X)
ans =
130 130
>> hist(X);
Each color represent one of those histograms, and yes, there are 130 of them. If you want just one histogram of all of the elements in the variable, then you can provide hist with one vector of values:
>> hist(X(:));

Products

Asked:

on 29 Mar 2017

Edited:

on 29 Mar 2017

Community Treasure Hunt

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

Start Hunting!