-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolorlock.m
86 lines (71 loc) · 1.82 KB
/
colorlock.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function colorlock
% (C) Nick Holschuh - University of Washington - 2016 (Nick.Holschuh@gmail.com)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are:
%
% ________ -
% ________ -
% ________ -
% ________ -
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The outputs are:
%
% ________ -
% ________ -
% ________ -
% ________ -
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The Dependencies are:
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Finds the most recently plotted image and locks in its color structure.
childs = get(gca,'Children');
for i = 1:length(childs)
if length(childs(i).Type) == 5
if childs(i).Type == 'image'
ci = i;
break
end
elseif length(childs(i).Type) == 7
if childs(i).Type == 'surface'
ci_delete = i;
break
end
end
end
if exist('ci') == 0
fr = getframe(gca);
NCData = fr.cdata;
xv_axis = get(gca,'XLim');
yv_axis = get(gca,'YLim');
xv = xv_axis;
yv = yv_axis;
yinf = get(gca,'YDir');
if length(yinf) == 6
NCData(:,:,1) = flipud(NCData(:,:,1));
NCData(:,:,2) = flipud(NCData(:,:,2));
NCData(:,:,3) = flipud(NCData(:,:,3));
end
if exist('ci_delete')
delete(childs(ci_delete));
end
else
xv = childs(ci).XData;
yv = childs(ci).YData;
[CData colors] = get_colormap_and_index;
NCData = ind2rgb(CData,colors);
xv_axis = get(gca,'XLim');
yv_axis = get(gca,'YLim');
yinf = get(gca,'YDir');
delete(childs(ci));
end
imagesc(xv,yv,NCData);
xlim(xv_axis)
ylim(yv_axis)
set(gca,'YDir',yinf)
end