获取给定值的颜色图颜色 [英] Get colormap color for a given value

查看:100
本文介绍了获取给定值的颜色图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有使用

scatter3(mx,my,mz,3,mx.^2+my.^2); % mx, my and mz are vectors

我看到C是一个与X和Y长度相同的向量,因此,根据文档,每个点的颜色应线性映射到当前颜色图中的颜色.

I see that C is a vector the same length as X and Y, so color of each point should be linearly mapped to the colors in the current colormap, per documentation.

我尝试过:

cmap = colormap;
disp(cmap(mx.^2+my.^2));

但是我得到了

Subscript indices must either be real positive integers or logicals.

有没有更简单的方法来解决此任务?

Is there any easier way to solve this quest?

谢谢

推荐答案

那很容易. Colormap不返回矢量,而是返回矩阵.这是因为每种颜色都有三个成分(红色,绿色和蓝色).

That's rather easy. Colormap does not return a vector, but a matrix. This is because each colour has three components (red, green and blue).

>> size(colormap)

ans =

    64     3

>> test = colormap;
>> test(7, :)

ans =

     0         0    0.9375

编辑...而且,我忘记了一些:索引必须以一种或另一种方式为整数.您可能希望将它们四舍五入或将它们变成整数.

EDIT ... And, I forgot something: The indices need to be integers, in one way or another. You may like to round them or turn them into an integer.

EDIT2 ...根据您的示例,disp语句的工作方式如下:

EDIT2 ... According to your example, the disp-statement works like this:

disp( cmap(1:( (size(cmap, 1)-1) / (length(mz)-1) ):size(cmap, 1), :) );

这篇关于获取给定值的颜色图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆