matlab Trisurf无法绘制到指定轴

j5fpnvbx  于 2023-01-09  发布在  Matlab
关注(0)|答案(2)|浏览(173)

我想通过函数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;

函数输入不像在函数surf中那样定义为varargin,因此无法将轴句柄指定为第一个输入变量。如果将轴句柄指定为第二个输入变量,函数axescheck将识别该句柄。但是后来我得到了一个错误,因为期望的第二个输入变量是一个向量。如果轴句柄被指定为第三个输入变量,函数axescheck根本不能识别句柄。
我知道我可以先激活轴,然后调用trisurf,但是我把它放在了一个循环中,所以这样做是不可取的,还有其他的解决方案吗?

kgsdhlau

kgsdhlau1#

如果你有你感兴趣的轴句柄,你可以做的是用axes(youraxeshandle)创建一个当前的轴,然后只使用trisurf而不需要任何特定的输入。它应该被添加到当前的轴,也就是你选择的轴。

xxe27gdn

xxe27gdn2#

既然这个问题还没有答案:
trisurf创建Patch对象,该对象与大多数图形对象一样,具有Parent属性。

% ax1 is the handle of you first axis
trisurf(k, x, y, z, 'Parent', ax1)

相关问题