function hh = trimesh(tri,x,y,z,varargin)
%TRIMESH Triangular mesh plot.
%   TRIMESH(TRI,X,Y,Z,C) displays the triangles defined in the M-by-3
%   face matrix TRI as a mesh.  A row of TRI contains indexes into
%   the X,Y, and Z vertex vectors to define a single triangular face.
%   The edge color is defined by the vector C.
%
%   TRIMESH(TRI,X,Y,Z) uses C = Z, so color is proportional to surface
%   height.
%
%   H = TRIMESH(...) returns a patch handle.
%
%   TRIMESH(...,'param','value','param','value'...) allows additional
%   patch param/value pairs to be used when creating the patch object. 
%
%   See also PATCH, TRISURF, DELAUNAY.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.14 $  $Date: 2000/06/02 04:30:48 $

ax = newplot;
start = 1;
if nargin>4 & rem(nargin-4,2)==1, 
  c = varargin{1};
  start = 2;
elseif nargin<4
  error('Not enough input arguments');
else
  c = z;
end

if isstr(get(ax,'color')),
  fc = get(gcf,'Color');
else
  fc = get(ax,'color');
end

h = patch('faces',tri,'vertices',[x(:) y(:) z(:)],'facevertexcdata',c(:),...
      'facecolor',fc,'edgecolor',get(ax,'defaultsurfacefacecolor'),...
      'facelighting', 'none', 'edgelighting', 'flat',...
      varargin{start:end});
if ~ishold, view(3), grid on, end
if nargout==1, hh = h; end
