MATLAB: How to apply a color gradient to an isosurface in a specified direction

MATLAB

I would like to use a colormap on an isosurface to show additional data about the surface. Specifically, I would like it to indicate the magnitude of the x-direction.

Best Answer

This bug has been fixed in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:
The following provides an example of how to apply color to an isosurface as a function of its magnitude in the x-direction, using the built-in FLOW data function:
[x,y,z,v] = flow;
[faces,verts,colors] = isosurface(x,y,z,v,-3,x);
patch('Vertices', verts, 'Faces', faces, ...
'FaceVertexCData', colors, ...
'FaceColor','interp', ...
'edgecolor', 'interp')
view(3)
Note that as x increases, the color goes from the dark blue to the red.
The sixth argument of ISOSURFACE provides a means to overlay another data set by applying color to the resulting isosurface. The “colors” variable is a vector containing a scale values for each vertex in the resulting isosurface to be used with the current color map. You can apply a different color scheme by changing the current figure color map. For example, enter the following at the MATLAB Command Prompt:
colormap hsv