MATLAB Answers

Assining fixed color for zero value

5 views (last 30 days)
Sarem.N
Sarem.N on 29 Oct 2019
Commented: Sarem.N on 29 Oct 2019
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?

  0 Comments

Sign in to comment.

Accepted Answer

Adam
Adam on 29 Oct 2019
Edited: Adam on 29 Oct 2019
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 Comment

Sarem.N
Sarem.N on 29 Oct 2019
Thats exactly what i want. Thanks a lot

Sign in to comment.

More Answers (0)

Products


Release

R2015b

Translated by