linearlyMapArrayToColors.m 300 B

1234567891011
  1. function colors = linearlyMapArrayToColors(xArray, colorMap)
  2. % Normalize to range 0-1.
  3. if ~range(xArray(:)) == 0
  4. xArray = (xArray - min(xArray(:))) / range(xArray(:));
  5. end
  6. nColors = size(colorMap, 1);
  7. colorInds = floor(xArray * (nColors - 1)) + 1;
  8. colors = colorMap(colorInds, :);
  9. end