I want the data above the specified threshold to be colored in the table (in app designer)

2 vues (au cours des 30 derniers jours)
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 commentaire
Ankit
Ankit le 2 Sep 2022
Modifié(e) : Ankit le 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

Connectez-vous pour commenter.

Réponses (1)

Rahul
Rahul le 14 Avr 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.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by