简体   繁体   English

Matlab:如何为冲浪图的单个单元着色

[英]Matlab: How to color single cell of a surf plot

I'm trying to differentiate the color of a single cell of a surf plot based on the Z function value, in particular: X, Y are (nxm) matrix and define a surface; 我试图基于Z函数值来区分冲浪图的单个单元格的颜色,特别是:X,Y是(nxm)矩阵并定义一个表面; Z is a ones(nxm) which has some particular points set to 3 or 4 or 5 Z是一个(nxm),其某些特定点设置为3或4或5

I'm trying to have a surf plot where the single grid cells with 3,4 or 5 value are colored differently then all the other surface grid cells. 我正在尝试制作一个冲浪图,其中具有3,4或5值的单个网格单元的颜色与所有其他曲面网格单元的颜色不同。

here's the code and the image I'm getting (in this specific case there's only 1 Z point with value =3): 这是我得到的代码和图像(在此特定情况下,只有1个Z点的值= 3):

在此处输入图片说明

figure;surf(X,Y,Z)

In this specific example my goal is to color RED the grid cell correspondent to the peak .Is there a way to obtain it? 在此特定示例中,我的目标是使与峰值对应的网格单元变为红色。是否有获取方法?

thnks in advance 提前thnks

As mentioned in the comments, colormap is the answer. 正如评论中提到的,颜色图就是答案。 The hard part is setting it up properly. 困难的部分是正确设置它。 The trick is to make the colormap larger than you need, say 10x3, make some bins inside colormap, and then scale your Z to fit into those bins. 诀窍是使颜色表大于所需的大小,例如10x3,在颜色表中创建一些箱,然后缩放Z以适合这些箱。 For example: 例如:

cmap(1, 1) = [0 0 0];
cmap(2:4, 1) = [0 0 1];
cmap(5:7, 1) = [0 1 0];
cmap(8:10, 1) = [1 0 0];
colormap(cmap);

This makes colormap bins, which you must fit your Z values into. 这将创建色图箱,您必须将其Z值放入其中。 You'll need to write the Z-value translation code. 您需要编写Z值转换代码。 You need to write something that turns any element of Z which is 5, for example, into 10. 您需要编写一些将Z的任何元素(例如5)变成10的内容。

I've done this for a similar problem using images, so if you work with me we can get you an exact answer. 我已经解决了使用图像的类似问题,因此,如果您与我合作,我们可以为您提供确切的答案。

Just to be sure 只是要确定

colormap(jet) 

doesn't work here? 在这里不工作? One of the ways i've done this is that in the GUI, you can manually edit teh colormap values in the colormap. 我执行此操作的方法之一是,在GUI中,您可以在颜色图中手动编辑颜色图值。

Then, just print out the colormap 然后,只需打印出颜色图

cmap = colormap

And then these values can be used in your function. 然后可以在您的函数中使用这些值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM