Trisurf无法绘制到指定轴

时间:2018-05-04 12:17:41

标签: matlab axis handle surface triangular

我想在函数trisurf中创建一个三角形曲面图,以指定轴为目标。但是,MATLAB文档并未指出任何语法。当我打开函数时,我得到以下第一行:

function hh = trisurf(tri,varargin)
%TRISURF Triangular surface plot
%   TRISURF(TRI,X,Y,Z,C) displays the triangles defined in the M-by-3
%   face matrix TRI as a surface.  A row of TRI contains indexes into
%   the X,Y, and Z vertex vectors to define a single triangular face.
%   The color is defined by the vector C.
%
%   TRISURF(TRI,X,Y,Z) uses C = Z, so color is proportional to surface
%   height.
%
%   TRISURF(TR) displays the triangles in the triangulation TR. It uses
%   C = TR.X(:,3) to color the surface proportional to height.
%
%   H = TRISURF(...) returns a patch handle.
%
%   TRISURF(...,'param','value','param','value'...) allows additional
%   patch param/value pairs to be used when creating the patch object. 
%
%   Example:
%
%   [x,y] = meshgrid(1:15,1:15);
%   tri = delaunay(x,y);
%   z = peaks(15);
%   trisurf(tri,x,y,z)
%
%   % Alternatively
%   tr = triangulation(tri, x(:), y(:), z(:));
%   trisurf(tr)
%
%   See also PATCH, TRIMESH, DELAUNAY, triangulation, delaunayTriangulation.
%   Copyright 1984-2017 The MathWorks, Inc.
narginchk(1,inf);
ax = axescheck(varargin{:});
ax = newplot(ax);
start = 1;

函数输入未定义为varargin,例如在函数surf中完成,因此无法将轴句柄指定为第一个输入变量。如果轴句柄被指定为第二个输入变量,函数axescheck会识别句柄,但后来我得到一个错误,因为预期的第二个输入变量是一个向量。如果将轴手柄指定为第三个输入变量,则函数axescheck根本无法识别手柄。

我知道我可以先激活轴,然后调用trisurf,但我在循环中有这个,所以不建议这样做。还有其他解决方案吗?

1 个答案:

答案 0 :(得分:0)

如果您拥有感兴趣的轴的手柄,那么您可以做的是使当前轴为axes(youraxeshandle),而只使用trisurf而没有任何特定输入。它应该添加到当前轴,即您选择的轴。