Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

bipolar.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. %BIPOLAR returns an M-by-3 matrix containing a blue-red colormap, in
  2. % in which red stands for positive, blue stands for negative,
  3. % and white stands for 0.
  4. %
  5. % Usage: cmap = bipolar(M, lo, hi, contrast); or cmap = bipolar;
  6. %
  7. % cmap: output M-by-3 matrix for BIPOLAR colormap.
  8. % M: number of shades in the colormap. By default, it is the
  9. % same length as the current colormap.
  10. % lo: the lowest value to represent.
  11. % hi: the highest value to represent.
  12. %
  13. % Inspired from the LORETA PASCAL program:
  14. % http://www.unizh.ch/keyinst/NewLORETA
  15. %
  16. % jimmy@rotman-baycrest.on.ca
  17. %
  18. %----------------------------------------------------------------
  19. function cmap = bipolar(M, lo, hi, contrast)
  20. if ~exist('contrast','var')
  21. contrast = 128;
  22. end
  23. if ~exist('lo','var')
  24. lo = -1;
  25. end
  26. if ~exist('hi','var')
  27. hi = 1;
  28. end
  29. if ~exist('M','var')
  30. cmap = colormap;
  31. M = size(cmap,1);
  32. end
  33. steepness = 10 ^ (1 - (contrast-1)/127);
  34. pos_infs = 1e-99;
  35. neg_infs = -1e-99;
  36. doubleredc = [];
  37. doublebluec = [];
  38. if lo >= 0 % all positive
  39. if lo == 0
  40. lo = pos_infs;
  41. end
  42. for i=linspace(hi/M, hi, M)
  43. t = exp(log(i/hi)*steepness);
  44. doubleredc = [doubleredc; [(1-t)+t,(1-t)+0,(1-t)+0]];
  45. end
  46. cmap = doubleredc;
  47. elseif hi <= 0 % all negative
  48. if hi == 0
  49. hi = neg_infs;
  50. end
  51. for i=linspace(abs(lo)/M, abs(lo), M)
  52. t = exp(log(i/abs(lo))*steepness);
  53. doublebluec = [doublebluec; [(1-t)+0,(1-t)+0,(1-t)+t]];
  54. end
  55. cmap = flipud(doublebluec);
  56. else
  57. if hi > abs(lo)
  58. maxc = hi;
  59. else
  60. maxc = abs(lo);
  61. end
  62. for i=linspace(maxc/M, hi, round(M*hi/(hi-lo)))
  63. t = exp(log(i/maxc)*steepness);
  64. doubleredc = [doubleredc; [(1-t)+t,(1-t)+0,(1-t)+0]];
  65. end
  66. for i=linspace(maxc/M, abs(lo), round(M*abs(lo)/(hi-lo)))
  67. t = exp(log(i/maxc)*steepness);
  68. doublebluec = [doublebluec; [(1-t)+0,(1-t)+0,(1-t)+t]];
  69. end
  70. cmap = [flipud(doublebluec); doubleredc];
  71. end
  72. return; % bipolar