0

我对 Matlab 编码有一个烦人的问题:我创建了一个存储值的 uitable,并且我实现了一个函数,用于在特定条件下突出显示单元格中的数字。这已经完成了给出一个 html 命令,问题是在设置新颜色后,“double”中的数字变为“单元格”并更新表中的数据,它正确突出显示值,但将所有数字对齐左边; 相反,我想让它们始终保持在正确的位置。我尝试了一切都没有积极的结果;我认为在 html 语法中添加对齐命令就足够了,但是有人可以给我一些建议吗?

这是代码的一部分:

tab = findobj('Tag',tab_name);
valrow = cellstr(num2str(tab.Data(index,1))); %number in the cell has to be highligthed
color = [1 1 0.4]; %yellow
clr = dec2hex(round(color*255),2)'; clr = ['#';clr(:)]';
valrow = strcat(...
          ['<html><body bgcolor="' clr '"text="#010101; font-weight: width=100px">'],...
          valrow);     %html code for highlight the number
fulltab = cellstr(num2str(tab.Data(:,1)));    %transform all the data in the table from double to cell
fulltab(index,1) = valrow;    % switch the old value in the tab with the same value highligthed
set(tab,'Data',[fulltab]);

正如我之前所说,此代码有效,但将表格中的所有数据从通常的右对齐到左对齐。

4

1 回答 1

0

我有同样的问题......然后我意识到宽度设置为 100% 而不是实际的单元格宽度。一旦我进行了更正,文本就会在宽度设置内对齐。

CellVal = strcat('',MaxOver,'');

于 2016-12-30T16:17:12.560 回答