You didn't follow the instructions given at the linked-to Answer. The 'BackgroundColor' property applies to the whole table; you have to use addStyle and a style object to modify individual cells.
See the following simple demonstration -- very similar to the example in the documentation but slightly more representative of your specific object.
M1=randn(4,1);M2=randn(4,1);M2(3)=M1(3);
hUF=uifigure;
hUIT1=uitable(hUF,'Data',M1,'Position',[20 20 120 120]);
hUIT2=uitable(hUF,'Data',M2,'Position',[160 20 120 120]);
sHiLite=uistyle;
sHiLite.BackgroundColor='green';
ix=find(M1==M2);
addStyle(hUIT1,sHiLite,'cell',[ix,1])
You'll need to build the auxiliary style object to turn the highlight color back to whatever you want for default if conditions change and relocate the matches.
Also, if this is floating point comparisons, you'll probably run into issues using "==" in finding exact matches. Look at ismembertol for "close enough" matching.
Follow the general pattern outlined above for your specific need; NB: addStyle works only in UIFigures.
If you're not using UIFIGURE, you'll have to resort to one of the kludges in the other thread...
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660553-how-to-change-cell-colors-in-uitable#comment_1158083
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660553-how-to-change-cell-colors-in-uitable#comment_1158083
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660553-how-to-change-cell-colors-in-uitable#comment_1158273
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660553-how-to-change-cell-colors-in-uitable#comment_1158273
Sign in to comment.