MATLAB: Map from value to colormap

colormap

I use pcolor to create a figure out of some matrix of data.
h=pcolor(X,Y,M);
Is it possible to receive for a specific index in the matrix in which color (RGB values) pcolor used (assuming a constant colormap)?
Or should i ask it – If I have a colormap and caxis – is there any function that will give me the color of a value (mapping from value to rgb value in the colormap)?
Thanks

Best Answer

Please check the solution provided at the below link by Jason D. Yeatman which does the exact thing that you want http://web.stanford.edu/~jyeatman/AFQ/doc/utilities/vals2colormap.html#_top
function rgb = vals2colormap(vals, colormap, crange)
0002 % Take in a vector of N values and return and return a Nx3 matrix of RGB
0003 % values associated with a given colormap
0004 %




0005 % rgb = AFQ_vals2colormap(vals, [colormap = 'jet'], [crange])
0006 %
0007 % Inputs:
0008 % vals = A vector of values to map to a colormap or a cell array of
0009 % vectors of values
0010 % colormap = A matlab colormap. Examples: colormap = 'autumn';
0011 % colormap = 'jet'; colormap = 'hot';
0012 % crange = The values to map to the minimum and maximum of the colormap.
0013 % Defualts to the full range of values in vals.
0014 %
0015 % Outputs:
0016 % rgb = Nx3 matrix of rgb values mapping each value in vals to the
0017 % corresponding rgb colors. If vals is a cell array then rgb
0018 % will be a cell array of the same length
0019 %
0020 % Example:
0021 % vals = rand(1,100);
0022 % rgb = AFQ_vals2colormap(vals, 'hot');
0023 %
0024 % Copyright Jason D. Yeatman, June 2012
Related Question