Changing the Surface Color Using the "surf" Command

234 Ansichten (letzte 30 Tage)
Alex Reyes
Alex Reyes am 13 Dez. 2020
Beantwortet: dileesh pv am 14 Dez. 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.

Antworten (1)

dileesh pv
dileesh pv am 14 Dez. 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;

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by