function [nn, xx] = hist_matrix(y, x)

%function [nn, xx] = hist_matrix(y, x)
%This plots histograms and is the same as the HIST but will allow y to
%be a matrix as well as a vector.  Unlike HIST NaNs are ignored.
%HIST_MATRIX
% 	HIST_MATRIX(Y) plots a histogram with 10 equally spaced bins
%       between the minimum and maximum values in Y, showing the
%       distribution of the elements in vector Y.
%	HIST_MATRIX(Y,N), where N is a scalar, uses N bins.
%	HIST_MATRIX(Y,X), where X is a vector, draws a histogram using
%       the bins specified in X.
%	[N,X] = HIST(...) does not draw a graph, but returns vectors
% 	X and N such that BAR(X,N) is the histogram.
% 
% 	See also BAR.



%     Copyright J. V. Mansbridge, CSIRO, october  5 1993

[m, n] = size(y);
xint = reshape(y, m*n, 1);
ind = ~isnan(xint);
yy = xint(ind);

if nargout == 0
  if nargin == 1
    hist(yy);
  elseif nargin == 2
    hist(yy, x);
  else
    disp([ num2str(nargin) ' input arguments passed to hist_matrix' ]);
  end
elseif nargout == 1
  if nargin == 1
    [nn] = hist(yy);
  elseif nargin == 2
    [nn] = hist(yy, x);
  else
    disp([ num2str(nargin) ' input arguments passed to hist_matrix' ]);
  end
elseif nargout == 2
  if nargin == 1
    [nn, xx] = hist(yy);
  elseif nargin == 2
    [nn, xx] = hist(yy, x);
  else
    disp([ num2str(nargin) ' input arguments passed to hist_matrix' ]);
  end
else
    disp([ num2str(nargout) ' output arguments passed to hist_matrix' ]);
end
