How to create a colormap attributing specific colour to each element?

6 ビュー (過去 30 日間)
Cassio Lima
Cassio Lima 2019 年 1 月 26 日
コメント済み: Cassio Lima 2019 年 1 月 28 日
Hi everyone!
I have an array A,
A = [ 1 2 3 4
2 2 3 1
1 1 4 2];
I want to create a colormap but each element needs to be colored in a specific colour, for example, 1 is blue, 2 is black, 3 is green and 4 is yellow.
Thanks

採用された回答

Matt Gaidica
Matt Gaidica 2019 年 1 月 26 日
Given these data, I would do this.
A = [ 1 2 3 4
2 2 3 1
1 1 4 2];
cmap = jet(max(A(:)));
figure;
imagesc(A);
colormap(cmap);
colorbar;
colormap.png

その他の回答 (1 件)

Stephen23
Stephen23 2019 年 1 月 27 日
編集済み: Stephen23 2019 年 1 月 27 日
A = [1,2,3,4;2,2,3,1;1,1,4,2];
map = [0,0,1;0,0,0;0,1,0;1,1,0]; % [blue;black;green;yellow]
imagesc(A,[1,4]) % better to set the color limits.
colormap(map)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by