Animated GIF of vector field coordinates in matlab

Alec Jacobson

August 26, 2013

weblog/

Suppose you have a mesh (V,F) and a vector field (or matrix of scalar field values) W. You can create a looping animated gif in matlab of a visualization of those values using:

t = trisurf(F,V(:,1),V(:,2),0*V(:,1),'EdgeColor','none','FaceColor','interp','FaceLighting','phong');
hold on;
  % for me each coordinate corresponds to a point in C
  scatter(C(:,1),C(:,2),'ok','MarkerFaceColor','y','LineWidth',3,'SizeData',100);
hold off;
axis equal;
view(2);
title('Vector Field  ','FontSize',20);
for w = 1:size(W,2)
  set(t,'CData',W(:,w));
  drawnow;
  im = myaa('raw');
  [imind,cm] = rgb2ind(im,256);
  filename = 'vector-field.gif';
  if w == 1;
    imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
  else
    imwrite(imind,cm,filename,'gif','WriteMode','append');
  end
end

This produces something like:

vector field animated gif matlab

Source