Suppose I am calculating the correlation of a a set of vectors.
Correlation[RandomReal[1, {5,5}]]
I would like to display the output using TableForm or Grid and use either Style or Background to highlight the entries that exceed some threshold (say > .5 and < -.5)
I found How can I add row and column header images to my TableForm output? which highlights the minimum in each row using:
TableForm[With[{min = Min[#]}, # /. min -> Style[min, Red]] & /@ data,
TableHeadings -> {ConstantArray[lena, 3], ConstantArray[lena, 9]}]
Can someone help me adapt this for my purpose?
Edit:
Of course I can do it this way:
data = RandomReal[1,{5,5}];
cors = Round[Correlation[data], .01];
Table[Style[cors[[i, j]],
If[Abs[cors[[i, j]]] > .35, Red, Black]], {i, 1, 5}, {j, 1, 5}] // TableForm
but I would like to understand how to do it in one line
Edit #2:
Here is the inelegant solution I came up with:
cors = Correlation[RandomReal[1, {5, 5}]];
headers = Table["Header " <> ToString[j], {j, 1, 5}];
backs = Table[ If[cors[[i, j]] > .35, {i + 1, j + 1} -> Green,
If[cors[[i, j]] < -.35, {i + 1, j + 1} -> Red]], {i, 1,
Length[cors]}, {j, 1, Length[cors]}] // Flatten;
Grid[MapThread[Prepend[#2, #1] &, {Join[{""}, headers], Prepend[
(Round[cors, .01]), headers]}],
Background -> {LightGray, LightGray, backs}, Frame -> All]
Which produces