MATLAB: Coloring of specific elements using trimesh

coloringtrimesh

Hi,
I'm using trimesh to plot a triangular mesh having all nodal positions stored in x,y,z and a corresponding nodal connection vector in Tri, generating a mesh following the trimesh-command as:
m = trimesh(Tri,X,Y,Z);
I understand how to use the handle m to change e.g. 'FaceColor' and 'EdgeColor' to a specific RGB-value. However, now I would like to color specific elements differently from the whole mesh. I.e. I have a list of all nodal points 'belonging' to a specific color and would like to somehow fix that using the trimesh-handle.
Anyone have an idea on how to achieve that?

Best Answer

I think the easiest way to do this would be to simply create two separate meshes, one that includes all points and one that only includes the ones you want to treat specially.
[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
isspecial = rand(size(tri,1),1) < 0.1;
trimesh(tri,x,y,z, 'facecolor', 'interp', 'edgecolor', 'k')
hold on
trimesh(tri(isspecial,:),x,y,z, 'facecolor', 'r')
Related Question