How to fix the mapping between colors and values?

조회 수: 5 (최근 30일)
zhehao.nkd
zhehao.nkd 2022년 1월 6일
답변: zhehao.nkd 2022년 1월 6일
I have a few matrices containing different integers, and I know all the possible intergers which can be found within these matrices. But not every integer will appear in each matrices, like:
% possible integers 0 1 2 3
x = randi([0 3],10,10); % from 0 to 3
y = randi([0 2],10,10); % from 0 to 2
z = randi([0 1],10,10); % from 0 to 1
Then how can I fix the mapping between matrix integers and RGB colors so that specific integer is always associated with specific color( as commented ) ?
cmap= [0 0 1;... % blue for 0
0 1 0;... % green for 1
1 0 0;... % red for 2
1 1 1]; % white for 3
figure;
imagesc(x);
colormap(cmap);
figure;
imagesc(y);
colormap(cmap);
figure;
imagesc(z);
colormap(cmap);

채택된 답변

zhehao.nkd
zhehao.nkd 2022년 1월 6일
I found out the solution by using
caxis manual
caxis([0,3]);
But the prerequisite is that the values should be linearlly distributed with the same gap in between.

추가 답변 (1개)

KSSV
KSSV 2022년 1월 6일
x = randi([0 3],10,10); % from 0 to 3
y = randi([0 2],10,10); % from 0 to 2
z = randi([0 1],10,10); % from 0 to 1
cmap= [0 0 1;... % blue for 0
0 1 0;... % green for 1
1 0 0;... % red for 2
1 1 1]; % white for 3
imagesc(x)
colormap(cmap)
colorbar

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by