Assining fixed color for zero value

15 visualizaciones (últimos 30 días)
Sarem.N
Sarem.N el 29 de Oct. de 2019
Comentada: Sarem.N el 29 de Oct. de 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?

Respuesta aceptada

Adam
Adam el 29 de Oct. de 2019
Editada: Adam el 29 de Oct. de 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 comentario
Sarem.N
Sarem.N el 29 de Oct. de 2019
Thats exactly what i want. Thanks a lot

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by