% gauss.m ---------------------------------------------------------
% This example script plots the results of combining uniform
% random variables.
% - Shows the advantage of setting the line data after the plt(..) call.
% - Note the use of the 'FigName' and 'TraceID' arguments.
% - Note the appearance of the greek letter in the x-axis label.
% - Uses the 'COLORdef' argument to select Matlab's default plotting
% colors (which are typically set to use a white background for the
% plotting area)
% - Shows how to use the 'Options' argument to enable the x-axis cursor
% slider (which appears just below the peak and valley finder buttons).
% - Uses the 'DIStrace' argument so that gauss.m starts off with some
% traces disabled.
% - Shows an example of the use of the 'MotionZoom' parameter. To see what
% it does, create a zoom box by holding both mouse buttons down and draging
% the mouse in the plot window. After releasing the mouse, you can make the
% zoom box disappear by right clicking in the main window.
% ----- Author: ----- Paul Mennen
% ----- Email: ----- paul@mennen.org
function gauss(a,xy)
mxN = 10; % sum up to 10 uniform distributions
traceID = ['Gauss'; reshape(sprintf('Sum%2d',2:mxN),5,mxN-1)'];
mainFig = 'Sum of uniform distributions';
if ~nargin % Initialize gauss window section ------------
dis = [0 0 0 ones(1,mxN-3)]; % initially just show the first 3 traces
h = plt(1,ones(1,mxN),'LabelX','Standard deviation (\sigma)','LabelY','',...
'TraceID',traceID,'MotionZoom','gauss',...
'COLORdef','default','FigName',mainFig,...
'DIStrace',dis,'xlim',[-4 4],'ylim',[-.05 1.05],'Options','S-X-Y');
sz = 100; % size of each uniform distribution
u = ones(1,sz); % uniform distribution
y = u; % y will be composite distribution
for n = 2:length(h)
y = conv(y,u); % convolve with next uniform distribution
m = length(y); mean = (m+1)/2; sigma = sz * sqrt(n/12);
x = ((1:m) - mean) / sigma; % change units to sigma (zero mean)
set(h(n),'x',x,'y',y/max(y));
end;
set(h(1),'x',x,'y',exp(-(x.^2)/2)); % gaussian distribution
else % zoom box motion function ------------------
zoomFig = 'Gauss Zoom Window';
f = findobj('name',zoomFig);
if isempty(f) % create the zoom window if it doesn't already exist
h = getappdata(gcf,'Lhandles'); x = get(h,'x'); y = get(h,'y');
plt(x{1},y{1},x{2},y{2},x{3},y{3},x{4},y{4},x{5}, y{5} ,...
x{6},y{6},x{7},y{7},x{8},y{8},x{9},y{9},x{10},y{10},...
'TraceID',traceID,'LabelX','','LabelY','',...
'Options','-All','FigName',zoomFig,...
'Position',[720 45 425 525],'AxisPos',[1.5,1,.9,1,1.6]);
f = gcf;
end;
ax = getappdata(f,'axis');
xlim = sort(xy(1:2)); ylim = sort(xy(3:4)); % get the limits of the zoom window
if diff(xlim)*diff(ylim) > 0 % ignore the limits if xmin==xmax or ymin==ymax
set(ax(1),'xlim',xlim,'ylim',ylim); % set the limits of the zoom axis
end;
figure(findobj('name',mainFig)); % restore focus to main window
end;