Changing the Surface Color Using the "surf" Command

244 views (last 30 days)
Hello,
I beginning to learn MATLAB and need to change the color of a surface I created using the "surf" command. My current code is as follows:
surf(X,Y,xPd,'FaceAlpha',0.5)
This works fine in creating the figure, I just need to change the color of the surface. The color itself does not matter as long as it stands out. I think I need to add a fourth variable after "xPD" but I am not sure what script to enter in specific. I have tried directly entering an RGB triplet into that space and creating a separate variable "C" defined as the RGB triplet and simply entering C into that space. Neither of which have worked. The vector defined as xPD is 13 by 13, which is obviously not the same size as the triplet. Does that have anything to do with the issue I am having? Thank you in advance.

Answers (1)

dileesh pv
dileesh pv on 14 Dec 2020
If you are looking for a single colored surface, use colormap to define the desired color;
Please see below an example;
[x,y,z] = peaks;
surf(x,y,z);
colormap([0 1 0]); % This is the RGB triplet for green. You can change this to desired triplet.
This will fetch you the following result;
Surf  with single colored surface
for other triplets; you can refer here: https://in.mathworks.com/help/matlab/ref/colormap.html
In case you need multiple selective colors on your colormap, you can send it those colors as given below;
colormap([0 0 0; 0 0 1; 0 1 0; 1 0 0; 1 1 1]);
The result will look as given below;

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!