1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- function [cmap] = cmaplevel(levels, colors, cmin, cmax, num_colors)
- if cmin > cmax
- cmap = [];
- return;
- elseif cmin == cmax
- [tilde, ind] = max(levels);
- cmap = repmat(colors(ind, :), [num_colors, 1]);
- return;
- end
- if ~isvector(levels)
- cmap = [];
- return;
- end
- t = horzcat(levels(:), colors);
- t = sortrows(t, 1);
- levels = t(:, 1);
- colors = t(:, 2:4);
- clevels = fix((levels-cmin)/(cmax-cmin)*num_colors) + 1;
- cmap = zeros(num_colors, 3);
- indices = find(clevels < 1, 1, 'last');
- indices = [indices find(clevels >= 1 & clevels <= num_colors)];
- for ind = indices:numel(levels)
- cmap(clevels(ind):num_colors, :) = repmat(colors(ind, :), [num_colors-clevels(ind)+1 1]);
- end
|