redblue.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. function c = redblue(m)
  2. %REDBLUE Shades of red and blue color map
  3. % REDBLUE(M), is an M-by-3 matrix that defines a colormap.
  4. % The colors begin with bright blue, range through shades of
  5. % blue to white, and then through shades of red to bright red.
  6. % REDBLUE, by itself, is the same length as the current figure's
  7. % colormap. If no figure exists, MATLAB creates one.
  8. %
  9. % For example, to reset the colormap of the current figure:
  10. %
  11. % colormap(redblue)
  12. %
  13. % See also HSV, GRAY, HOT, BONE, COPPER, PINK, FLAG,
  14. % COLORMAP, RGBPLOT.
  15. % Adam Auton, 9th October 2009
  16. if nargin < 1, m = size(get(gcf,'colormap'),1); end
  17. if (mod(m,2) == 0)
  18. % From [0 0 1] to [1 1 1], then [1 1 1] to [1 0 0];
  19. m1 = m*0.5;
  20. r = (0:m1-1)'/max(m1-1,1);
  21. g = r;
  22. r = [r; ones(m1,1)];
  23. g = [g; flipud(g)];
  24. b = flipud(r);
  25. else
  26. % From [0 0 1] to [1 1 1] to [1 0 0];
  27. m1 = floor(m*0.5);
  28. r = (0:m1-1)'/max(m1,1);
  29. g = r;
  30. r = [r; ones(m1+1,1)];
  31. g = [g; 1; flipud(g)];
  32. b = flipud(r);
  33. end
  34. c = [r g b];