Domanda

I am trying to create an array of numbers (converted to string) that fall bellow a thresh hold, for my current testing i'm using 0.5. I need the font of every value of my table that falls above or below my thresh hold to be colored red, in my current code i'm only using 2 columns, but I will be using more than 10. This is my code right now and it is only displaying the numbers values above 0.5 in color red but it's not displaying the numbers below 0.5 (they should be in black). I'm sorry for the bad naming of the variables, I'm just testing to implement this. Help will be greatly appreciated.

TTT = rand(30,2);
for u = 1:2

PPP = TTT(1:30, u:u);

   RRR = ( PPP(:) > .5);

   AAA = reshape(strtrim(cellstr(num2str(TTT(:)))), size(TTT));

   QQQQ(RRR, u) = strcat(...
   '<html><span style="color: #FF0000; font-weight: bold;">', ...
    AAA(RRR, u), ...
   '</span></html>');


end
%# 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',QQQQ) 
È stato utile?

Soluzione

You are not filling all values in QQQQ, only those which will be in red. The rest (which should be in black) are left as empty cells, and thus they are not shown.

To correct this, You need to initialize QQQQ to AAA, and then modify color for the relevant cells. So, add

AAA = reshape(strtrim(cellstr(num2str(TTT(:)))), size(TTT));
QQQQ = AAA;

right before the for loop, and remove the AAA = reshape... line from within the loop. That is:

TTT = rand(30,2);
AAA = reshape(strtrim(cellstr(num2str(TTT(:)))), size(TTT));
QQQQ = AAA;
for u = 1:2
   PPP = TTT(1:30, u:u);
   RRR = ( PPP(:) > .5);
   QQQQ(RRR, u) = strcat(...
      '<html><span style="color: #FF0000; font-weight: bold;">', ...
      AAA(RRR, u), ...
      '</span></html>');
end

%# 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',QQQQ) 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top