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

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 24 Feb. 2022

Beantwortet:

am 14 Apr. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by