Assining fixed color for zero value

조회 수: 16 (최근 30일)
Sarem.N
Sarem.N 2019년 10월 29일
댓글: Sarem.N 2019년 10월 29일
i have a 2D matrix A(i,j). each value in this matrix can be the integers between 1:n for examle. some cells are equal to zero and i need an image plot of A but with black color for zero values. is it possible in matlab?

채택된 답변

Adam
Adam 2019년 10월 29일
편집: Adam 2019년 10월 29일
Define a colourmap of size n, assuming n is not huge, and then add black to the front of it
n = 7;
colourmap = [0 0 0; parula( n )];
Then, e.g.
myData = randi(n, 20 ) - 1;
figure; imagesc( myData );
colormap( colourmap )
caxis( [-0.5 n + 0.5] )
  댓글 수: 1
Sarem.N
Sarem.N 2019년 10월 29일
Thats exactly what i want. Thanks a lot

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by