Matlab's trisurf confuses face colors with vertex colors

Alec Jacobson

July 28, 2013

weblog/

I recently had trouble getting matlab's trisurf to display interpolated colors inside each face. I was calling:
set(trisurf(F,V(:,1),V(:,2),V(:,3)),'FaceColor','interp');
But the display looked like flat shading. The problem turned out to be that I had 9 faces and 9 vertices. In this rare instance matlab decides that the vertex colors (which actually are just the Z coordinates in V(:,3)) should be attached (incorrectly) to the faces and are not interpolatable. I hacked a fix to this by appending an extra ghost vertex:
set(trisurf(F,[V(:,1);0],[V(:,2);0],[V(:,3);0]),'FaceColor','interp');