MATLAB: How to color a surface plot

3d plotssurface plots

I have plotted a surface plot using meshgrid as shown below
However I want to change the color to the ones shown in the example on mathworks: http://in.mathworks.com/help/matlab/learn_matlab/creating-mesh-and-surface-plots.html, I have surf too, but it didn't work. Can anyone please help me?

Best Answer

My guess is that you are referring to the plot in the Colored Surface Plots section of that documentation, created by this code:
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
surf(X,Y,Z)
colormap hsv % <— Specify ‘colormap’ To Override Default
colorbar
You need to add this line:
colormap hsv
to your code to get the same colormap as in the example plot.