如何根据表中的数据(在Matlab中)修改合适的单元格颜色?

发布于 2024-12-04 10:58:26 字数 441 浏览 0 评论 0原文

我有一个 matlab 函数,它以 uitable.txt 形式返回结果。

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

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

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

附: 我知道以下页面:

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

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

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

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.

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.

Is there a way to do this using just Matlab?

PS:
I am aware of the following page:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

超可爱的懒熊 2024-12-11 10:58:26

如果您仔细阅读讨论,您会发现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)

截图

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

Here is an example:

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)

screenshot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文