MATLAB: How to paint a surface according to another scalar function

3d plotscolorMATLABsurface

Dear experts,
Assume I am given with the surface: z=4-x-y^2 . I now want every point on the surface to be colored according to a function: R(x,y,z).
Is there any simple way to make such a coloring?
Thanks a lot in advance!

Best Answer

Something like this?
[x,y] = meshgrid(linspace(-2,2,50));
z = 4-x-y.^2;
c = x.^2 - y;
surf(x,y,z,c)