MATLAB: For UITABLE: BackgroundColor for row

backgroundcoloruitableuitable color

hello,
i have problem in GUI, for UITABLE the BackgroundColor are for every row but i want BackgroundColor for every colomn please help me,
.
for exemple:
f = figure('Position', [100 100 752 350]); t = uitable('Parent', f, 'Position', [25 25 700 200]);
set(t, 'Data', magic(10));
foregroundColor = [1 1 1]; set(t, 'ForegroundColor', foregroundColor); backgroundColor = [.4 .1 .1; .1 .1 .4]; set(t, 'BackgroundColor', backgroundColor);
.
thank you in advance
faithfully;

Best Answer

You cannot directly set colors per column (unless it can be done at the Java level.)
The work-around is to change the column to string format, convert the numeric values to string, and wrap each string with an HTML code to change the color.
bgcols = floor(255 * [.4 .1 .1;.1 .1 .4]);
colfmtstr = sprintf('<HTML><TABLE><TD bgcolor="rgb(%d,%d,%d)"%%g', bgcols(1,:));
colcontents = cellstr( num2str(magic(10), colfmtstr) );
then make colcontents one of the columns of the data. Change the color for a different column by changing the (1,:) to (2,:)