-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mat2Colormap.m
45 lines (38 loc) · 1.32 KB
/
Mat2Colormap.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
function ColorMatrix = Mat2Colormap(Matrix,ColorMap,Mode)
%The input matrix is used to map to a specified colormap
%If Matrix is a 2D matrix, ColorMatrix will be a 3D matrix with the third dimension as RGB
%If Matrix is an array, you know what you get
%function MyMatrix = tsnePlot(Matrix,'jet','Symmetric');
%Mode can be 'Symmetric' or not. Symmetric means middle color has to represent 0, useful for fold change display
if nargin < 2
ColorMap='jet';
end;
if nargin < 3
Mode='Asymmetric';
end;
[m n]=size(Matrix);
test2=discretize(Matrix,64);
if strcmp(Mode,'Symmetric')==1
if (max(max(Matrix)')-min(min(Matrix)')) >= 0
test2=discretize([Matrix;repmat(-max(max(Matrix)'),1,n)],64);
elseif (max(max(Matrix)')-min(min(Matrix)')) < 0
test2=discretize([Matrix;repmat(-min(min(Matrix)'),1,n)],64);
end;
test2(end,:)=[];
end;
MyMap=colormap(ColorMap);
[m n]=size(test2);
for i=1:m
for j=1:n
test3R(i,j)=MyMap(test2(i,j),1);
test3G(i,j)=MyMap(test2(i,j),2);
test3B(i,j)=MyMap(test2(i,j),3);
end;
end;
ColorMatrix=test3R;
ColorMatrix(:,:,2)=test3G;
ColorMatrix(:,:,3)=test3B;
if m==1 || n==1
ColorMatrix=reshape(ColorMatrix,max(m,n),3);
end;
end