2012-10-16 89 views
1

我想設置在單元格背景顏色的細胞..MATLAB設置背景色uicontrol

類似:

enter image description here

所以我有RGB顏色和我想要着色的單元格的數量。

你可以認爲單元格的位置是我寫的。

我的顏色是由RGB給出:

color = [255 0 0]; 

我想將其添加到第10電池,所以我寫了類似:

S.cell_data(10) = uicontrol('style','text',... 
       'units','pix',... 
       'Position',[20 70 80 40],... 
       'string',color); 

但風格是不是「文本」和它不是一個字符串。

這就是我想現在:

S.cell_data(10) = uicontrol('style','text',... 
       'units','pix',... 
       'Position',[125 70 80 40],... 
       'string','fh'); 

parentColor = get(get(S.cell_data(10), 'parent'), 'color'); 

set(S.cell_data(num_of_cols+1),'foregroundcolor', [0 0 0], ... 
    'backgroundcolor', parentColor); 

有人知道?

+0

請詳細說明,不清楚。 –

+0

我添加了一個例子:] –

回答

2
blue = 255; 
green = 0; 
red = 0; 

rgb_str = strcat('<HTML><BODY bgcolor = "rgb(', num2str(red), ', ', num2str(green), ', ', num2str(blue), ')">green background</BODY></HTML>'); 

S.cell_data(10) = uicontrol('Style','pushbutton', 'Position',[20 70 80 40], 'String', {rgb_str}); 
+1

你不需要strcat(只是使用方括號),我不認爲在調用uicontrol時強制轉換爲單元格字符串是必要的,但除此之外:使用html的良好演示uicontrol。 –

+1

請注意,在matlab uicontrols中使用HTML標記是未記錄的,並且在將來的版本中可能不起作用。 –

+0

謝謝你們倆。 –