imagesc an integer 2d array using particular colors
조회 수: 1 (최근 30일)
이전 댓글 표시
I would like to draw a 2d array of integers whose values are only from the set {11,12,21,22,23,24,31,41,42,43,51,52,71,72,73,74,81,82,90,95} using the corresponding colors in the figure below (attached). For instance dark red for 24 and yellow for 81 as can be seen from the figure. How can I do this in MATLAB?

댓글 수: 0
답변 (1개)
Walter Roberson
2017년 8월 16일
Construct a color map that has at least 95+1 entries, and store the RGB corresponding to integer N at row N+1; for example, put the entry corresponding to color 52 in row 53 of the color map. You can put any handy thing into the other entries (e.g. 0 0 0)
Then you can either
image( uint8(YourArray) );
colormap( TheColorMap );
or
imshow( uint8(YourArray), TheColorMap );
There are other ways as well, but the above ways easily preserve the values that will show up if you use the data cursor.
The reason for adding 1 is that when you using uint8(), the value 0 corresponds to the first entry, the value 1 corresponds to the second entry, and so on.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Blue에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!