MATLAB: How to retrieve RGB array from a colormap given a CData

cdatacolormapMATLABrgb

Hello,
If I have a designated colormap, jet for example, and the caxis is set to [0 1] and I want to return the RGB values (array of three numbers) of CData 0.5, how can I do this?
Thanks!

Best Answer

Isn't it just half way up your colormap? So if you specify 256 colors
cmap = jet(256);
and the first row cmap(1,:) applies to 0, and the last row cmap(256,:) applied to values of 1, then 0.5 will be the middle row of your colormap (green if you chose jet). See:
grayImage = imread('moon.tif');
grayImage = im2double(grayImage);
imshow(grayImage);
cmap = jet(256);
colormap(gca, cmap);
colorbar;
% Find the middle row, which corresponds to an image value of 0.5
middleRow = round(size(cmap, 1) / 2)
% Print the color there out to the command window:
cmap(middleRow, :)
% Shows ans = 0.5 1 0.5 (green color as expected);