Assining fixed color for zero value

12 Ansichten (letzte 30 Tage)
Sarem.N
Sarem.N am 29 Okt. 2019
Kommentiert: Sarem.N am 29 Okt. 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?

Akzeptierte Antwort

Adam
Adam am 29 Okt. 2019
Bearbeitet: Adam am 29 Okt. 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 Kommentar
Sarem.N
Sarem.N am 29 Okt. 2019
Thats exactly what i want. Thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by