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 = histogram(r,numbins);
Create a new Array Plot object.
scope = dsp.ArrayPlot;
Configure the properties of the Array Plot object to plot a histogram.
scope = dsp.ArrayPlot; scope.XOffset = 0; scope.SampleIncrement = 1/numbins; scope.PlotType = 'Stem'; scope.YLimits = [0, max(hst)+1];
Call the scope 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
release method to let property
values and input characteristics change. At the MATLAB command line, type:
Change the configuration of the Array Plot properties for the display of a distribution function.
numbins = 201; numtrials = 100; r = zeros(numsamples,1); scope.SampleIncrement = 1/numbins; scope.PlotType = 'Stairs';
Call the scope repeatedly to plot the uniform distribution.
for ii = 1:numtrials r = rand(numsamples,1)+r; hst = histogram(r/ii,0:1/numbins:1); scope.YLimits = [min(hst)-1, max(hst)+1]; scope(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.