Reputation: 161
Based on this question: Table fields in format in PDF report generator - Matlab, I converted the p
table to be a DOM MATLAB Table. How can I color the header row, remove the underlining of its entries and apply the tableStyle
on the rest of it.
With my code, I get all the table with the LightBlue
color and the tableStyle
is not applied.
Code:
function ButtonPushed(app, event)
import mlreportgen.dom.*;
import mlreportgen.report.*
ID = [1;2;3;4;5];
Name = {'San';'John';'Lee';'Boo';'Jay'};
Index1 = [1;2;3;4;5];
Index2 = [176.23423;163.123423654;131.45364572;133.5789435;119.63575647];
Index3 = [176.234;16.123423654;31.45364572;33.5789435;11.6647];
p = table(ID,Name,f(Index1),f(Index2),f(Index3));
V = @(x) inputname(1);
p.Properties.VariableNames(3:end) = {V(Index1), V(Index2), V(Index3)};
headerStyle = { BackgroundColor("LightBlue"), ...
Bold(true) };
tableStyle = { Width("60%"), ...
Border("single"), ...
RowSep("solid"), ...
ColSep("solid") };
p = MATLABTable(p)
p.Style = headerStyle;
p.TableEntriesHAlign = 'center';
d = Document('myPDF','pdf');
d.OutputPath = ['E:/','temp'];
append(d,'Report for file: ');
append(d,p);
close(d);
rptview(d.OutputPath);
end
function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting at each tab
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (empty) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end
Upvotes: 0
Views: 788
Reputation: 19689
You defined the variable tableStyle
in which you defined the desired properties but you didn't set them. Also instead of setting the header as bold and light blue background, you are setting all the entries to have that.
The following code fixes that:
set(p, 'Width', '60%', 'Border', 'single',...
'RowSep', 'solid', 'ColSep', 'solid',...
'TableEntriesHAlign', 'center');
p.HeaderRule = ''; %To remove the underlining of header entries
p.Header.Style = headerStyle; %Setting the Header Style
Upvotes: 1