How can I export a Matlab 2D array in Conditional Formatted table in pdf using MATLAB Report Generator?

조회 수: 3 (최근 30일)
I have some 2D array in Matlab. And I wanted to export this array in pdf in 3 Colour scheme Conditional Formated Table as shown below. How can I do that?
I have searched a code that generate the zebra strip tables. Does there exist such codes to auto do Conditional Formating (Like in Excel)?
I am new to MATLAB Report Generator,How can I achive this task?
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('zebraTable','pdf');
maglen = 8;
mag = magic(maglen);
tb = Table(mag);
% Set the colors for alternating rows
for i = 1:maglen
r = tb.row(i);
if mod(i,2)==0
r.Style = {BackgroundColor('lightsteelblue')};
else
r.Style = {BackgroundColor('white')};
end
end
tb.Style={RowHeight('0.3in'),RowSep('solid'),ColSep('solid')};
tb.Width= '3in';
tb.TableEntriesVAlign = 'middle';
tb.TableEntriesHAlign = 'center';
tb.Border = 'single';
add(rpt,tb)
close(rpt)
rptview(rpt)

채택된 답변

Rahul Singhal
Rahul Singhal 2021년 2월 18일
Hi Masood,
In the sample script that you provided, you can just update the for-loop to provide conditional formatting for each table entry based on the content of the entry. Below is an example:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('zebraTable','pdf');
maglen = 8;
mag = magic(maglen);
tb = Table(mag);
% Conditional formatting for table entries
nRows = tb.NRows;
nCols = tb.NCols;
for iRow = 1:nRows
for iCol = 1:nCols
entry = tb.entry(iRow,iCol);
entryContent = entry.Children.Content;
% Provide as many cases you want based on the entry content value
if entryContent < 25
entry.Style = {BackgroundColor('red')};
else
entry.Style = {BackgroundColor('green')};
end
end
end
tb.Style={RowHeight('0.3in'),RowSep('solid'),ColSep('solid')};
tb.Width= '3in';
tb.TableEntriesVAlign = 'middle';
tb.TableEntriesHAlign = 'center';
tb.Border = 'single';
add(rpt,tb)
close(rpt)
rptview(rpt)
Hope this helps!
Thanks,
Rahul

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by