如何根据表格中的数据修改适合的单元格颜色(在Matlab中)? [英] How to modify uitable cell color according to data in table (in Matlab)?

查看:1403
本文介绍了如何根据表格中的数据修改适合的单元格颜色(在Matlab中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个matlab函数,该函数以uitable返回结果.

I have a matlab function that returns results in a uitable.

该表有2列和很多行:第一列是值",第二列是安全阈值/置信区间".

There are 2 columns and lots of rows to the table: first column is "values" and second column is a "safety threshold/confidence interval" of sorts.

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

I'd like to format the output so that certain cells get painted red: those for which the "value" in column 1 exceeds the corresponding "safety threshold" in column 2.

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

Is there a way to do this using just Matlab?

PS: 我知道以下页面:

PS: I am aware of the following page:

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

但是对我来说似乎很麻烦,而且我希望自从发布该文章以来,Matlab可能已经赶上并内置了此功能?

but it seems like a lot of tinkering to me, and I'm hoping that since that post was made, maybe Matlab has caught up and brought this functionality built in?

推荐答案

如果您阅读了讨论 UITABLE 支持HTML内容...

If you read the discussion carefully, you'll find out that UITABLE supports HTML content...

这里是一个例子:

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)

这篇关于如何根据表格中的数据修改适合的单元格颜色(在Matlab中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆