Assining fixed color for zero value

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 日

0 投票

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 件)

カテゴリ

製品

リリース

R2015b

タグ

質問済み:

2019 年 10 月 29 日

コメント済み:

2019 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by