MATLAB Answers

imagesc an integer 2d array using particular colors

3 views (last 30 days)
MatG
MatG on 16 Aug 2017
Answered: Walter Roberson on 16 Aug 2017
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 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 16 Aug 2017
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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!