1

I would like to make a triangular surface plot throught the function trisurf, targeting a specified axis. However, MATLAB documentation does not indicate any syntax to do that. When I open the function I get the following first lines:

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;

The function input is not defined just as varargin, as it is done in function surf for example, so it is not possible to specify the axis handle as first input variable. If the axis handle is specified as second input variable, the function axescheck recognize the handle, but later I get an error because the expected second input variable is a vector. If the axis handle is specified as third input variable the function axescheck does not recognize the handle at all.

I know that I can first activate the axis and then call trisurf, but I have this inside a loop so it is not advisable to do that. Is there any other solution?

fma
  • 219
  • 2
  • 14

2 Answers2

0

If you have the axes handle of the one you are interested in, what you can do is make the current axis that one byaxes(youraxeshandle), and the just use trisurf without any specific input. It should be added to the current axis, which is the one you selected.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Yep, this is what I meant with first activating the axis and then calling `trisurf`. However this is not efficient in a loop. With other plotting functions in fact it is possible to target an axis without making it current axis. I was wondering if there is a solution to do this with `trisurf` as well. – fma May 04 '18 at 13:08
  • @Francesco I think this is your only option, unfortunately – Ander Biguri May 04 '18 at 14:06
0

Since this is still unanswered:

trisurf creates a Patch object, which like most graphical objects, has a Parent property.

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