Changing the Surface Color Using the "surf" Command
212 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
dileesh pv
2020-12-14
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;
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!