How to convert a vector to rgb colormap?

27 ビュー (過去 30 日間)
Ali Nouri
Ali Nouri 2019 年 12 月 30 日
コメント済み: Image Analyst 2020 年 1 月 2 日
Hello guys
can anybody tell me how to convert a ector to rgb colormap??
I have have vector, which its value goes from -1 to 1. I want the define a colormap, where the value of the 0.2 to 1 is red and -0.2 to -1 is blue and the rest is green.
thanks in advance.

採用された回答

Image Analyst
Image Analyst 2019 年 12 月 30 日
Do this:
% Colormap "where the value of the 0.2 to 1 is red and
% -0.2 to -1 is blue, and the rest is green.
numColors = 256;
vec = linspace(-1, 1, numColors);
cmap = zeros(numColors, 3);
% Make everything green to start with
cmap(:, 2) = 1;
% Make red from where vec goes from 0.2 to 1.
redIndexes = vec >= 0.2 & vec <= 1;
cmap(redIndexes, 1) = 1;
cmap(redIndexes, 2) = 0;
cmap(redIndexes, 3) = 0;
% Make blue from where vec goes from -1 to -0.2.
blueIndexes = vec >= -1 & vec <= -0.2;
cmap(blueIndexes, 1) = 0;
cmap(blueIndexes, 2) = 0;
cmap(blueIndexes, 3) = 1;
cmap % Echo to command window so we can see it.
  19 件のコメント
Ali Nouri
Ali Nouri 2020 年 1 月 2 日
what about now? I have upload the cntry.02
Image Analyst
Image Analyst 2020 年 1 月 2 日
Sine I don't have the toolbox, I don't have shaperead() and so I can't continue.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by