function eg = higram(pmtr,scale)
%
% higram: return histogram of non-zero elements of array
% On input:
%     pmtr: matrix
%     scale: multiplied times the values (the bigger the value, the greater
%            detail
% On output:
%     eg: count of number of each array value
% Call:
%     eg = higram(matrix,scale)
%

mtr = m2v(pmtr);
[n m] = size(mtr);

if scale>0
  for ii = 1:n
    for jj=1:m
      if mtr(ii,jj)>0
        mtr(ii,jj) = floor(scale*mtr(ii,jj));
      end
    end
  end
end

rm = max(max(mtr));
eg(rm) = 0;

index = 0;
for ii = 1:n
  for jj = 1:m
    if mtr(ii,jj) > 0
      eg(mtr(ii,jj)) = eg(mtr(ii,jj)) + 1;
    end
  end
end

plot(eg);
