Changing the Surface Color Using the "surf" Command

254 vues (au cours des 30 derniers jours)
Alex Reyes
Alex Reyes le 13 Déc 2020
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.

Réponses (1)

dileesh pv
dileesh pv le 14 Déc 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;

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by