Set the background of an variable specific item in a Grid

I have a Grid in which I want to modify the background of the minimum value of the last row. For that purpose, I have create a variable with the position of the minimum value of this row "PosicionECMMin = Position[ECMEst, Min[ECMEst]]" but that does not work. Can anyone help me. I attached an image where you can see what I want. Thank you very much.

{EspEst, VarEst, ECMEst} = RandomReal[1, {3, 4}]
PosicionECMMin = Position[ECMEst, Min[ECMEst]]

Grid[{{"",
"T1",
"T2",
"T3",
"T4"},
Prepend[EspEst, "Esperanza"], Prepend[VarEst, "Varianza"],
Prepend[ECMEst, "ECM"]}, Frame -> All, Alignment -> Center,
Spacings -> 2,
Background -> {None, None, {4, PosicionECMMin + 1} -> Green}]

• ECMEst has numeric values as you can see in the image that I have attached. To see the value of the "PosicionECMMin" I have printed his value and I have seen that It is correct but when I put this variable into the Background code, it does not work. Thanks. Commented Oct 29, 2017 at 20:11

You got the position specification wrong. PosicionECMMin + 1 in your answer is not the scalar it is supposed to be.

As M. Stern points out, the most straightforward way to fix this is to replace

PosicionECMMin = Position[ECMEst, Min[ECMEst]]


PosicionECMMin = Position[ECMEst, Min[ECMEst]][[1, 1]]


This also works:

{EspEst, VarEst, ECMEst} = RandomReal[1, {3, 4}];
PosicionECMMin =
Prepend[FirstPosition[ECMEst, Min[ECMEst]], 4] + {0, 1};

Grid[{
{"", "T1", "T2", "T3", "T4"},
Prepend[EspEst, "Esperanza"],
Prepend[VarEst, "Varianza"],
Prepend[ECMEst, "ECM"]
},
Frame -> All,
Alignment -> Center,
Spacings -> 2,
Background -> {None, None, PosicionECMMin -> Green}
]


Another approach would be to not use the Background property, but to use Item instead:

PosicionECMMin = FirstPosition[ECMEst, Min[ECMEst]];
ECMEst = ReplacePart[ECMEst,
PosicionECMMin ->
Item[Extract[ECMEst, PosicionECMMin], Background -> Green]]

Grid[{
{"", "T1", "T2", "T3", "T4"},
Prepend[EspEst, "Esperanza"],
Prepend[VarEst, "Varianza"],
Prepend[ECMEst, "ECM"]
},
Frame -> All,
Alignment -> Center,
Spacings -> 2
]


The Item approach can also be used with TableForm:

{EspEst, VarEst, ECMEst} = RandomReal[1, {3, 4}];
PosicionECMMin = FirstPosition[ECMEst, Min[ECMEst]];
ECMEst = ReplacePart[
ECMEst,
PosicionECMMin -> Item[Extract[ECMEst, PosicionECMMin], Background -> Green]
];

TableForm[
{EspEst, VarEst, ECMEst},
TableHeadings -> {{"Esperanza", "Varianza", "ECM"}, {"T1", "T2", "T3", "T4"}}
]


Beware that the Item approach modifies ECMEst. If you intend to keep doing other work with ECMEst then you'll want to copy the values to another variable first.

• or simply add [[1,1]] after Position[ECMEst, Min[ECMEst]] Commented Oct 29, 2017 at 23:45
• @M.Stern In OP's original version, yes. Not in my versions. Commented Oct 30, 2017 at 2:17
• Yes. Now that I think about it.. using FirstPosition is better in general Commented Oct 31, 2017 at 17:01