1

so a small version of what I am trying to accomplish is I have a matrix A;

A = [0 1 0; 2 0 0;1 3 6;9 0 1];
imagesc(A)

So when I use imagesc(A) I get a nice grid with each value represented by a different color. However I want to be able to set the value of 0 specifically to white and ideally be able to change the other colors as I see fit such as if I know two values represent the same thing like 3 and 6, then they could be set to the same or relatively similar colors. Is imagesc the wrong command to use because from what I can tell it uses a color gradient.

Thanks

nsoures
  • 25
  • 1
  • 3

2 Answers2

1

2 options:

  1. you can create your own colormap as shown in How to create a custom colormap programmatically?
  2. or simply map your matrix A to a matrix that would be coloured as you want it. So if you know you want 3 and 6 to the same colour then create a mapping function that makes that so. You then use A to index the map so the 3rd and 6th element of map must be the same e.g.

    map = [1, 2, 3, 4, 5, 6, 4, 7, 8, 9, 10];
    imagesc(map(A+1))
    

    note that elements 4 and 7 in map are the same because your A values start from 0, this is also why there is the +1 in the second line.

    and then just choose a colormap that starts from white.

Personally I would go with method 1.

Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157
  • Thanks, sorry I dont know how I didn't find that first one i'm new to this site and programming in general, either way problems solved so thanks again. – nsoures Oct 02 '15 at 00:27
0

Simple solution:

% get colormap and set first value to white
cmap = colormap;    
cmap(1,:) = [1 1 1];

% apply new colormap
colormap(cmap);

% display matrix 
imagesc(A);

Obviously you can change the colors for other values in the same way

gregswiss
  • 1,456
  • 9
  • 20