0

I have a correlation Matrix outputed by the corr(X) function.

I need to display it in an RGB image format with the following specs.

Negative correlation should be red and possitive correlation should be green. The values of the correlation matrix are in the range of [ -1 , 1 ].


1 -0,0286473845495979 0,185190317331816
-0,0286473845495979 1 -0,309327144422681
0,185190317331816 -0,309327144422681 1


I convert the matrix to the range of [ -255 , 255 ] and I need to display the negative values in red and the possitive values in green, with the corresponding color intensity ...


0 -262 208
-262 0 -334
208 -334 0


Any help would be great !

1 Answers1

0
red = [1,0,0];
green = [0,1,0];

R = linspace(red(1),green(1),256);
G = linspace(red(2),green(2),256);
B = linspace(red(3),green(3),256);

map = [R', G', B'];
colormap(map)
colorbar

See How to create a custom colormap programmatically? for an explanation. Also you'll notice it goes a yellowy-brown in the middle. If you don't want this then I suggest either making the middle black or white, the answer I linked to should explain how to achieve that.

Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157