-
Notifications
You must be signed in to change notification settings - Fork 0
/
jp_cmap2.m
57 lines (44 loc) · 1.42 KB
/
jp_cmap2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function cmap = jp_cmap2(hotColor, coolColor, midColor, nSteps)
%JP_CMAP2 Colormap generator for two colors ("HOT" and "COLD").
%
% CMAP = JP_CMAP2 provides default red/blue colormap.
%
% CMAP = JP_CMAP2(HOT, COLD) lets you specify the RGB values for
% the HOT and COLD values. If any number in a color is > 1, the
% values are divided by 255. (This allows you to specify in standard RGB
% values 0-255, or Matlab values 0-1.)
%
% CMAP = JP_CMAP2(HOT, COLD, MID) uses the specified color for the
% middle color (i.e., a 0 value). Default is white.
%
% CMAP = JP_CMAP2(HOT, COLD, MIDCOLOR, NSTEPS) uses the specified
% number of steps to go from MIDCOLOR to HOT or COLD (default 100).
if nargin < 4 || isempty(nSteps)
nSteps = 100;
end
if nargin < 3 || isempty(midColor)
midColor = [1 1 1];
end
if nargin < 2 || isempty(coolColor)
coolColor = [51 153 255]/255;
end
if nargin < 1 || isempty(hotColor)
hotColor = [205 102 102]/255;
end
if max(coolColor) > 1
coolColor = coolColor/255;
end
if max(hotColor) > 1
hotColor = hotColor/255;
end
hotcmap = zeros(nSteps,3);
coolcmap = zeros(nSteps,3);
hotcmapStep = (hotColor - midColor)/nSteps;
coolcmapStep = (coolColor - midColor)/nSteps;
hotcmap(1,:) = hotColor;
coolcmap(1,:) = coolColor;
for q = 2:nSteps
hotcmap(q,:) = hotcmap(q-1,:) - hotcmapStep;
coolcmap(q,:) = coolcmap(q-1,:) - coolcmapStep;
end
cmap = flipud([hotcmap; midColor; flipud(coolcmap)]);