1
votes

I want to draw a color map with three columns in matlab. I can draw with plot3 like below,

x = [1 1 1 1 2 2 2 2 4 4 4 4 5 5 5 5 9 9 9 9]; 
y = [2 3 4 5 5 6 7 8 4 5 6 7 1 2 3 4 7 8 9 10];
z = [1 3 2 4 5 6 7 3 9 8 8 9 2 4 3 5 1 2 3 1];
plot3(x, y, z, 'o')

But how can I draw 2D color map with three columns?

1
You are using that word, colormap, it may not mean what you think it means. In that line, you are not using a colormap. - Ander Biguri
Can you hand draw (in paint for example) an example of what you want and post it a link to it? - Dan
Even if you are not using colormaps, if you want to do the same thing you are doing but in 2D you should plot(x,y,'o') - Ander Biguri
Hi Ander and Dan, thanks for your comments, below answer from Bla shows what I want. :) - Seokhan Kim

1 Answers

3
votes

Option 1:

If I understand you correctly you want to draw a 2D array (say m(x,y)) where the color is given by z. this is how:

m=zeros(max(x),max(y));    % preallocate m according to values of x,y
m(sub2ind(size(m),x,y))=z; % assign z-values to the x,y coordinates
imagesc(m)                 % plot
colormap(pink(max(z)));    % set colormap with the dynamic range of z.
                           % you can replace it with jet or whatever...
colorbar                   % add a colorbar

enter image description here

Option 2:

you really just want to create am RGB colormap from x,y,z:

cmap=[x(:) y(:) z(:)]./max([x(:);y(:);z(:)]);
imagesc(peaks(100)); 
colormap(cmap);

enter image description here