Setting Custom Colors Using imagesc function

5 Ansichten (letzte 30 Tage)
Kristen
Kristen am 17 Nov. 2011
I am using imagesc() to look at different sections of a matrix of 0's, 1's, and 2's. Imagesc sets the lowest value (always 0 in this case) to blue, the largest value to red, and the intermediate value to green. Some sections of the matrix have all three values (0,1,2), some have only 0 and 1, and some have only 0 and 2. I want to have set colors for 1 and 2 (0 is always blue). For example, when the section of matrix has only 0 and 1, the 1's show up red. When the section of matrix has only 0 and 2, the 2's show up red. I want the 1's to always show up green and the 2's to always show up red, despite whether there are only 1's or only 2's in the section of matrix. Any suggestions? Thanks.

Antworten (1)

Walter Roberson
Walter Roberson am 17 Nov. 2011
colormap([0 0 1; 0 1 0; 1 0 0]);
image(uint8(YourArray))

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by