Setting Custom Colors Using imagesc function

5 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2011-11-17
colormap([0 0 1; 0 1 0; 1 0 0]);
image(uint8(YourArray))

类别

Help CenterFile Exchange 中查找有关 Color and Styling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by