Save a Uitable with coloured cells as as png.

2 views (last 30 days)
Alessandro Togni
Alessandro Togni on 28 Apr 2021
Answered: Adam Danz on 28 Apr 2021
Hi, i've created a Uitable object and colured its cells with this code:
app.UITable.Data=CreateUITable(app, app.deltas_table, app.deltas_threshold);
% Hightlight over-threshold values in red
[redRows, redCols]= find( abs(app.UITable.Data{:,2}) >= app.deltas_threshold);
z = uistyle('BackgroundColor',[1 0.6 0.6]);
addStyle(app.UITable, z ,'cell',[redRows, redCols]);
addStyle(app.UITable, z ,'cell',[redRows, redCols+1]);
addStyle(app.UITable, z ,'cell',[redRows, redCols+2]);
addStyle(app.UITable, z ,'cell',[redRows, redCols+3]);
% Hightlight under-threshold values in green
[greenRows, greenCols]= find( abs(app.UITable.Data{:,2}) <= app.deltas_threshold);
n = uistyle('BackgroundColor',[0.6 1 0.6]);
addStyle(app.UITable, n ,'cell', [greenRows, greenCols]);
addStyle(app.UITable, n ,'cell',[greenRows, greenCols+1]);
addStyle(app.UITable, n ,'cell',[greenRows, greenCols+2]);
addStyle(app.UITable, n ,'cell',[greenRows, greenCols+3]);
% Hightlight NaN values in gray
NaNidxs = ismissing(app.UITable.Data);
[NaNrow,NaNcol] = find(NaNidxs);
s = uistyle('BackgroundColor',1/255*[200,200,200]);
addStyle(app.UITable,s,'cell',[NaNrow, NaNcol]);
addStyle(app.UITable,s,'cell',[NaNrow, NaNcol+1]);
addStyle(app.UITable,s,'cell',[NaNrow, NaNcol+2]);
addStyle(app.UITable,s,'cell',[NaNrow, NaNcol+3]);
Now i want to save the table on a .png (or pdf) file.
Any help would be really appreciated.

Answers (1)

Adam Danz
Adam Danz on 28 Apr 2021
One solution is to put the uitable within a uipanel and then use exportgraphics to export the table.
If you want to export the entire figure you don't need to embed the table within a panel.


Community Treasure Hunt

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

Start Hunting!