Showing results for 
Search instead for 
Did you mean: 

Problems with

Hello, I am creating a program to use 4 random number generators to simulate coin flips. I have a for loop to simulate a certain number of trials, and I want to plot the results of this trial as a histogram. Ie: Show how many times 0,1,2,3,4 heads are flipped for the total number of trials. I am running into odd problems. When I probe the input data to the histogram for a certain trial it's {3,1,1,1,2,1,3,3,2,3} and the histogram outputs {4,0,2,0,4} yet it should clearly be {0,4,2,4,0}. It is able to count the frequency correctly apparently, it simply orders it wrong. Attached is the .VI of my project. Any thoughts?

0 Kudos
Message 1 of 3

Hello Raldikuk,


As per the Help documentation on the histogram function, the default minimum and maximum bins created will correspond to the minimum and maximum values provided in the input array.  In this case, it sounds like you are expecting bins corresponding to 0,1,2,3,and 4, whereas the bins created automatically should in fact be closer to 1,1.75,3,3.75,4 in the example case described in your post (this will depend on the data set provided.)


I would recommend using the Histogram graph (right-click on the's Histogram Graph cluster output>>create>>indicator), as this more explicitly represents the bins, and you may want to take a look at the General Histogram function (also in the Probability & Statistics palette) if you want to specify the bins yourself.


I hope that helps!




Tom L.
0 Kudos
Message 2 of 3

It looks like the histogram function is working as it should.  The context help explains why it is functioning as it is.  However, I took a look at your code to see what I could do with it and came up with this, please take a look. 

0 Kudos
Message 3 of 3