I want the data above the specified threshold to be colored in the table (in app designer)
    4 views (last 30 days)
  
       Show older comments
    
d=table2array(app.data);
            d=rmmissing(d);
            [Coeff,P]=corrcoef(d);
            app.UITable5.ColumnName=app.VarNames;
            app.UITable5.Data=Coeff;
            app.UITable5.RowName=app.VarNames; 
            app.UITable6.ColumnName=app.VarNames;
            app.UITable6.Data=P;
            app.UITable6.RowName=app.VarNames;
            nr=size(app.UITable5.Data,1);
            nc=size(app.UITable5.Data,2);
            t=app.TCorrelationEditField.Value;
            for i=1:nr
                for j=1:nc
                    if app.UITable5.Data(i,j)>=t
                        app.UITable5.BackgroundColor(i,j)=[1 0 0];
                    end
                end
            end
1 Comment
  Ankit
      
 on 2 Sep 2022
				
      Edited: Ankit
      
 on 2 Sep 2022
  
			which MATLAB version you are using?
app.OutputTable.BackgroundColor; % this will return the uitable background color
Add style to table or tree UI component - MATLAB addStyle - MathWorks Deutschland - if you are using version 2019a (here you can find some example too
Answers (1)
  Rahul
      
 on 14 Apr 2025
        The functionality regarding adding a background colour to those cells of 'uitable' in App Designer which are above a certain threshold can be achieved in the following way:
- Creating a 'uistyle' object to target the 'BackgroundColor'.
- Iterating through a loop to check if the cell data is within the desired threshold or not.
- If condition is satisfied the using 'addStyle' function to apply the 'uistyle' to the particular cell in the table.
Here is an example:
threshold = 50; 
% Create a style object
style = uistyle('BackgroundColor', 'red');
% Loop through the data and apply coloring
for row = 1:numRows
    for col = 1:numCols
        cellValue = data{row, col};
        if isnumeric(cellValue) && cellValue >= threshold
            addStyle(app.UITable, style, 'cell', [row, col]);
        end
    end
end
The following MathWorks documentations can be referred to know more:
Thanks.
0 Comments
See Also
Categories
				Find more on Develop Apps Using App Designer in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

