How to modify uitable cell color according to data in table (in Matlab)?

前端 未结 1 1032
温柔的废话
温柔的废话 2020-12-09 13:41

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 \"s

1条回答
  •  [愿得一人]
    2020-12-09 14:36

    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(...
        '', ...
        XX(idx,1), ...
        '');
    
    %# 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

    0 讨论(0)
提交回复
热议问题