I'm using a Delaunay triangularization to convert a scatter plot to a surface. To animate this plot, I want to update the trisurf handle instead of creating a new trisurf plot to reduce overhead and to increase the plotting speed.
Basically, in a for loop, I want to update the properties of the trisurf handle h to obtain the same plot that calling trisurf again would yield.
MWE
x = linspace(0,1,11);
y = x;
[X,Y] = meshgrid(x,y);
mag = hypot(X(:),Y(:)); % exemplary magnitude
T = delaunay(X(:),Y(:));
z = 0
h = trisurf(T, X(:), Y(:), z*ones(size(X(:))), mag, 'FaceColor', 'interp'); view([-90 90]);
for i = 1:10
% Compute new values for X, Y, z, and mag
% -> Update properties of handle h to redraw the trisurf plot instead
% of recalling the last line before the for loop again, e.g.,
% h.FaceVertexCData = ...
% h.Faces = ...
% h.XData = ...
end
You can change a few properties of the Patch object returned by
trisurf():where
zis assumed to always be a scalar, just like in the original call totrisurf().set()calls usingVerticescan be some 20% faster thanset()calls usingXDataand related properties, and that these strategies are about an order of magnitude faster than multipletrisurf()calls. When the number of x/y-positions is allowed to vary from 2 to 200, however, run times are about the same for the three approaches.