Changing live uitable row colours depending on value.

I'm using a live uitable object to read out data from an Arduino and write it into a table, using a callback function. I want give the rows a specific color, depending on the value in one of the columns. I did get it to work with addStyles, but I noticed that this command significantly slows down my code, to the point where it's not useable to me. Is there another way to do this, for example by changing a table property?

回答 (2 件)

Voss
Voss 2024 年 3 月 25 日
編集済み: Voss 2024 年 3 月 25 日

0 投票

Since you are coloring by row, setting the uitable's BackgroundColor may work for you.
You can use a matrix of colors. Example:
figure
t = uitable('Data',randi(10,4,3));
t.BackgroundColor = [1 0 0; 1 1 0; 0 1 0; 0 1 1];
If the table has more rows than there are rows in BackgroundColor, then the colors are repeated as necessary:
figure
t = uitable('Data',randi(10,4,3));
t.BackgroundColor = [1 0 0; 1 1 0; 0 1 0; 0 1 1];
t.Data(end+10,:) = 0;
Alternatively, you may be able to speed up your code that uses addStyle if you make sure to removeStyle any uistyle when it is no longer needed.
Sofia
Sofia 2025 年 11 月 6 日

0 投票

What if I want cell in the same row to be of different color?
How can I do this?

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2024 年 3 月 25 日

回答済み:

2025 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by