Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB更新trisurf句柄_Matlab_Surf_Delaunay - Fatal编程技术网

MATLAB更新trisurf句柄

MATLAB更新trisurf句柄,matlab,surf,delaunay,Matlab,Surf,Delaunay,我正在使用Delaunay三角化将散点图转换为曲面。要设置此绘图的动画,我想更新trisurf句柄,而不是创建新的trisurf绘图,以减少开销并提高绘图速度 基本上,在for循环中,我想更新trisurfhandleh的属性,以获得再次调用trisurf将产生的相同绘图 MWE x = linspace(0,1,11); y = x; [X,Y] = meshgrid(x,y); mag = hypot(X(:),Y(:)); % exemplary magnitude T = delaun

我正在使用Delaunay三角化将散点图转换为曲面。要设置此绘图的动画,我想更新
trisurf
句柄,而不是创建新的
trisurf
绘图,以减少开销并提高绘图速度

基本上,在for循环中,我想更新
trisurf
handle
h
的属性,以获得再次调用
trisurf
将产生的相同绘图

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


您可以更改由
trisurf()
返回的修补程序对象的一些属性:

其中,假定
z
始终是标量,就像最初调用
trisurf()
一样

  • 问:这些选项是否同样快
  • 答:我在我的计算机(R2019a,Linux)上运行了一些测试(见下面的代码),发现当x/y位置的数量是2到20之间的随机数时,使用
    顶点的多个
    set()
    调用比使用
    XData
    和相关属性的
    set()
    调用快20%左右,这些策略比多次调用
    trisurf()
    要快一个数量级。但是,当x/y位置的数量允许在2到200之间变化时,三种方法的运行时间大致相同
for i = 1:9
  % Compute new values for X, Y, z, and mag
  % As an example:
  x = linspace(0,1,11-i);
  y = x;
  [X,Y] = meshgrid(x,y);
  mag = hypot(X(:),Y(:));
  T = delaunay(X(:),Y(:));

  z = i;
  Z = z*ones(size(X)); %we could have just called `meshgrid()` with 3 arguments instead
  % End recomputation

  % Update trisurf() patch: option 1
  set( h, 'Faces',T, 'XData',X(T).', 'YData',Y(T).', 'ZData',Z(T).', 'CData',mag(T).' );
  pause(0.25); %just so we can see the result
  % Update trisurf() patch: option 2
  set( h, 'Faces',T, 'Vertices',[X(:) Y(:) Z(:)], 'FaceVertexCData',mag(:) );
  pause(0.25); %just so we can see the result
end
Nruns=1e3;
Nxy_max=20;

for i=1:Nruns
  if i==round(Nruns/10)
    tic(); %discard first 10% of iterations
  end
  x = linspace(0,1,randi(Nxy_max-1)+1); %randi([2,Nxy_max]) can be a bit slower
  [X,Y,Z] = meshgrid(x,x,randn());
  mag = hypot(X(:),Y(:));
  T = delaunay(X(:),Y(:));
  trisurf(T, X(:), Y(:), Z(:), mag, 'FaceColor', 'interp');
  view([-90 90]);
end
tmean_trisurf=1e3*toc()/(Nruns-round(Nruns/10)+1), %in [ms]

h=trisurf(T, X(:), Y(:), Z(:), mag, 'FaceColor', 'interp');
view([-90 90]);

for i=1:Nruns
  if i==round(Nruns/10)
    tic();
  end
  x = linspace(0,1,randi(Nxy_max-1)+1);
  [X,Y,Z] = meshgrid(x,x,randn());
  mag = hypot(X(:),Y(:));
  T = delaunay(X(:),Y(:));
  set( h, 'Faces',T, 'XData',X(T).', 'YData',Y(T).', 'ZData',Z(T).', 'CData',mag(T).' );
end
tmean_xyzdata=1e3*toc()/(Nruns-round(Nruns/10)+1), %in [ms]

for i=1:Nruns
  if i==round(Nruns/10)
    tic();
  end
  x = linspace(0,1,randi(Nxy_max-1)+1);
  [X,Y,Z] = meshgrid(x,x,randn());
  mag = hypot(X(:),Y(:));
  T = delaunay(X(:),Y(:));
  set( h, 'Faces',T, 'Vertices',[X(:) Y(:) Z(:)], 'FaceVertexCData',mag(:) );
end
tmean_vertices=1e3*toc()/(Nruns-round(Nruns/10)+1), %in [ms]