필터 지우기
필터 지우기

How to set specific values in an array to a certain color when using imagesc?

조회 수: 12 (최근 30일)
Caleb Jacobus
Caleb Jacobus 2018년 11월 20일
댓글: Stephen23 2020년 3월 20일
I have an array that is 100x100 filled with zeros. I want to set some cells to other values and have the cell change colour depending on the value.
i want cells that have a value of 1 to be green, a value 2 to be white, 3 to be brown and 0 to be blue.
how would i do this?

답변 (1개)

Miriam
Miriam 2018년 11월 20일
You can define your own colormap as follows:
x = randi([0 3],10,10);
colors = [0 0 1;... % blue for 0
0 1 0;... % green for 1
1 1 1;... % white for 2
0.65 0.16 0.16]; % brown for 3, etc.
figure;
imagesc(x);
colormap(colors);
  댓글 수: 2
Selva Kumar
Selva Kumar 2020년 3월 20일
When there is no '1' or '2' in the matrix 'x', then this colormap doesnot work as intended.
Any solution for this issue ?

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by