This example shows how to use and configure the
visualize the Central Limit Theorem. This theorem states that the
mean of a large number of independent random variables with finite
mean and variance exhibits a normal distribution.
numsamples = 1e4; numbins = 20; r = rand(numsamples,1); hst = hist(r,numbins);
Create a new Array Plot object.
hap3 = dsp.ArrayPlot;
Configure the properties of the Array Plot object to plot a histogram.
hap3 = dsp.ArrayPlot; hap3.XOffset = 0; hap3.SampleIncrement = 1/numbins; hap3.PlotType = 'Stem'; hap3.YLimits = [0, max(hst)+1];
step method to plot the uniform distribution.
The following Array Plot figure appears, showing a uniform distribution.
Next, calculate the mean of multiple uniformly distributed random
variables. As the number of random variables increases, the distribution
more closely resembles a normal curve. Run the
to let property values and input characteristics change. At the MATLAB command
Change the configuration of the Array Plot properties for the display of a distribution function.
numbins = 201; numtrials = 100; r = zeros(numsamples,1); hap3.SampleIncrement = 1/numbins; hap3.PlotType = 'Stairs';
step method repeatedly to plot the uniform
for ii = 1:numtrials r = rand(numsamples,1)+r; hst = hist(r/ii,0:1/numbins:1); hap3.YLimits = [min(hst)-1, max(hst)+1]; step(hap3,hst'); pause(0.1); end
When the simulation has finished, the Array Plot figure displays a bell curve, indicating a distribution that is close to normal.
The zoom tools allow you to zoom in simultaneously in the directions of both the x- and y-axes or in either direction individually. For example, to zoom in on the distribution between 0.3 and 0.7, you can use the Zoom X option.
To activate the Zoom X tool, select Tools > Zoom X, or press the corresponding toolbar button ( ). You can determine if the Zoom X tool is active by looking for an indented toolbar button or a check mark next to the Tools > Zoom X menu option.
Next, zoom in on the region between 0.3 and 0.7. In the Array Plot window, click on the 0.3-second mark, and drag to the 0.7-second mark. The display reflects this new x-axis setting, as shown in the following figure.