function k = convhulln(x)
%CONVHULLN N-D Convex hull.
%   K = CONVHULLN(X) returns the indices K of the points in X that 
%   comprise the facets of the convex hull of X. X is an m-by-n array 
%   representing m points in n-D space. If the convex hull has p facets
%   then K is p-by-n+1. 
%
%   CONVHULLN is based on Qhull.
%
%   See also CONVHULL, QHULL, DELAUNAYN, VORONOIN, TSEARCHN, DSEARCHN.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.9 $ $Date: 2000/08/28 15:53:21 $

[m,n] = size(x);
if m < n+1,
  error('Not enough points to do tessellation.');
end
if any(isnan(x(:)) | isinf(x(:)))
  error('Data containing Inf or NaN, cannot be tessellated.');
end
if m == n+1
  k = 1:n+1;
  return
end

k = qhullmx(x', 'QJ ', 'Pp');

