-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomColormap.m
More file actions
28 lines (22 loc) · 880 Bytes
/
customColormap.m
File metadata and controls
28 lines (22 loc) · 880 Bytes
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
function customColormap = customColormap(nColors)
% Define desired color values at specific points
colors = [ ...
0.2 0.2 1; % Light blue for negative values
1 1 1; % White around 0
1 1 0.8; % Yellow for low positive values
1 0.8 0.4; % Orange for mid-range positive values
1 0 0; % Red for high positive values
];
% Define values representing color transitions
values = linspace(-0.8, 1.6, size(colors, 1));
% Create empty colormap array
customColormap = zeros(nColors, 3);
% Define new values linearly spaced throughout the desired range
newValues = linspace(-0.8, 1.6, nColors);
% Use interp1 to interpolate color across specified values
for i = 1:3
interpolatedValues = interp1(values, colors(:, i), newValues);
% Ensure RGB values are within [0, 1] range
customColormap(:, i) = max(0, min(1, interpolatedValues));
end
end