forked from cultpenguin/mGstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colormap_nan.m
70 lines (58 loc) · 1.1 KB
/
colormap_nan.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
58
59
60
61
62
63
64
65
66
67
68
69
70
% colormap_nan
%
% Replaces all NaN values with a specific color, and rescales the
% colorbar appropriately;
%
%
% example :
% d=peaks(200);
% d(find(d<0))=NaN;
% figure(1);
% im=imagesc(d);
% colormap(hot);
% colormap_nan(im);
% drawnow;
%
%
% figure(2);
% im=imagesc(d);
% colormap(jet);
% colormap_nan(im,[.2 .9 .1]);
% colorbar;drawnow;
%
%
%
%
function colormap_nan2(im,nancolor,method)
if nargin<2
nancolor=[1 1 1];
end
if nargin<1
return
end
if nargin<3
method=1;
end
if length(im)==1
Cdata=get(im,'Cdata');
else
Cdata=im;
end
%find(isnan(Cdata))=nan_val;
nanmap=Cdata.*0;
nanmap(find(isnan(Cdata)))=1;
if method==1
set(im,'alphadata',1-nanmap)
else
cax=caxis;
nan_val=cax(1)-(cax(2)-cax(1));
Cdata(find(isnan(Cdata)))=nan_val;
set(im,'Cdata',Cdata);
cmap=colormap;
nc=size(cmap,1);
cmap(1,:)=[nancolor]
colormap(cmap);
dperc=-2/nc;
colormap_squeeze([dperc,0]);
end
return