7

我有一个 matlab 函数,它返回一个 uitable 的结果。

该表有 2 列和许多行:第一列是“值”,第二列是“安全阈值/置信区间”。

我想格式化输出,以便某些单元格被涂成红色:第 1 列中的“值”超过第 2 列中相应的“安全阈值”的单元格。

有没有办法只使用 Matlab 来做到这一点?

PS:我知道以下页面:

http://www.mathworks.de/matlabcentral/newsreader/view_thread/150507

但这对我来说似乎有很多修补工作,我希望自从那篇文章发表以来,也许 Matlab 已经赶上了并内置了这个功能?

4

1 回答 1

10

如果您仔细阅读讨论,您会发现UITABLE支持 HTML 内容...

这是一个例子:

X = rand(100,2);

%# convert matrix of numbers to cell array of strings (right aligned)
XX = reshape(strtrim(cellstr(num2str(X(:)))), size(X));

%# find cells matching condition
idx = ( X(:,1) > X(:,2) );

%# use HTML to style these cells
XX(idx,1) = strcat(...
    '<html><span style="color: #FF0000; font-weight: bold;">', ...
    XX(idx,1), ...
    '</span></html>');

%# create table
f = figure;
h = uitable('Parent',f, 'Units','normalized', 'Position',[0.05 0.05 0.9 0.9]);

%# set table data
set(h, 'Data',XX)

截屏

于 2011-09-14T01:43:36.637 回答