Question

I have a problem in customizing colors of a surface plot (trisurf or trimesh).

I would like every face to have a color depending on the relative strain value (calculated for every triangle of the mesh). I was thinking about something like:

p = patch('Faces',faces,'Vertices',verts,'FaceColor',strain);

But FaceColor seems not to work with arrays.

strain is an array of Nx1 where N is the number of faces.

Was it helpful?

Solution

First you need to change FaceColor to 'flat' to enable colours to be read from a color-data array - the CData property:

Try this (not tested though):

p = patch( ...
   'Faces',     faces, ...
   'Vertices',  verts, ...
   'FaceColor', 'flat', ...
   'CData',     strain' ...
);

Here I set the CData property to the transpose of your strain vector. MATLAB should then automatically map the N strain-values in this vector to the chosen colormap (linearly). See property CDataMapping for more information:

Documentation:

http://www.mathworks.se/help/matlab/ref/patch_props.html#FaceColor http://www.mathworks.se/help/matlab/ref/patch_props.html#CData http://www.mathworks.se/help/matlab/ref/patch_props.html#CDataMapping

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top