function y = histogram(x, n) % y=histogram(x,n) - calculate a histogram of values of x. % x must be positive, histogram starts at zero. % Faster than hist() (why?). n = round(n); y = zeros(1, n); N = size(x, 2); mx = max(x); for i = 1:N index = round (1 + x(i) * (n-1) / mx); y(index) = y(index) + 1; end