Home > wafo > wstats > whisto.m

# whisto

## PURPOSE

Plots a histogram

## SYNOPSIS

binwidth = whisto(x,N,odd,scale,lintype)

## DESCRIPTION

``` WHISTO Plots a histogram

CALL:  binwidth = whisto(x,N,odd,scale)

binwidth = the width of each bin
x = the data
N = approximate number of bins wanted
(default depending on length(x))
odd = placement of bins (0 or 1) (default 0)
scale = argument for scaling (default 0)
scale = 1 yields the area 1 under the histogram
lintype : specify color and lintype, see PLOT for possibilities.

Example:
R=wgumbrnd(2,2,[],1,100);
whisto(R,20,0,1)
hold on
x=linspace(-3,16,200);
plot(x,wgumbpdf(x,2,2),'r')
hold off```

## CROSS-REFERENCE INFORMATION

This function calls:
 hold Hold current graph. ishold Return hold state. off plot Linear plot.
This function is called by:
 Chapter1 % CHAPTER1 demonstrates some applications of WAFO Chapter3 % CHAPTER3 Demonstrates distributions of wave characteristics kde1dgui GUI to Kernel Density Estimator. wafofig3 Probability density distributions (pdf) of wave period, Tt,

## SOURCE CODE

```001 function binwidth = whisto(x,N,odd,scale,lintype)
002 %WHISTO Plots a histogram
003 %
004 % CALL:  binwidth = whisto(x,N,odd,scale)
005 %
006 %        binwidth = the width of each bin
007 %               x = the data
008 %               N = approximate number of bins wanted
009 %                   (default depending on length(x))
010 %             odd = placement of bins (0 or 1) (default 0)
011 %           scale = argument for scaling (default 0)
012 %                   scale = 1 yields the area 1 under the histogram
013 %         lintype : specify color and lintype, see PLOT for possibilities.
014 %
015 % Example:
016 %   R=wgumbrnd(2,2,[],1,100);
017 %   whisto(R,20,0,1)
018 %   hold on
019 %   x=linspace(-3,16,200);
020 %   plot(x,wgumbpdf(x,2,2),'r')
021 %   hold off
022 %
023
024
025
026 % References:
027 %  Holtsberg, Anders (1999)
028 %  Stixbox. A statistics toolbox for Matlab and Octave.
029 %  Lund University
030 %  http://www.maths.lth.se/matstat/stixbox
031
032 % Tested on: Matlab 5.3
033 % History:
034 % Revised by es 31.03.2000 Added default in help + lintype
035 % Revised by jr 22.12.1999
036
037 if nargin < 2, N = []; end
038 if nargin < 3, odd = []; end
039 if nargin < 4, scale = []; end
040 if nargin < 5, lintype = []; end
041
042 if isempty(N),       N = ceil(4*sqrt(sqrt(length(x))));end
043 if isempty(odd),     odd = 0;end
044 if isempty(scale),   scale = 0;end
045 if isempty(lintype), lintype = 'b-';end
046
047
048 mn = min(x);
049 mx = max(x);
050 d = (mx - mn)/N*2;
051 e = floor(log(d)/log(10));
052 m = floor(d/10^e);
053 if m > 5
054    m = 5;
055 elseif m > 2
056    m = 2;
057 end
058 d = m * 10^e;
059 mn = (floor(mn/d)-1)*d - odd*d/2;
060 mx = (ceil(mx/d)+1)*d + odd*d/2;
061 limits = mn:d:mx;
062
063 f = zeros(1,length(limits)-1);
064 for i = 1:length(limits)-1
065    f(i) = sum(x>=limits(i) & x<limits(i+1));
066 end
067
068 xx = [limits; limits; limits];
069 xx = xx(:);
070 xx = xx(2:length(xx)-1);
071 yy = [f*0; f; f];
072 yy = [yy(:); 0];
073 if scale, yy = yy/length(x)/d; end
074
075 H = ishold;
076 plot(xx,yy,lintype)
077 hold on
078 plot(limits,limits*0)
079 if ~H hold off, end
080
081 if nargout > 0
082    binwidth = d;
083 end
084
085
086```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003