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

5 ビュー (過去 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 Center および File ExchangeMATLAB Report Generator についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by