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

4 次查看(过去 30 天)
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 个)

Rahul
Rahul 2025-4-14
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.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by