How to Join Tables in report generator?

6 views (last 30 days)
If the code goes like this:
import mlreportgen.dom.*
tablecontent1 = { ... };
table1 = Table(tablecontent1);
...
tablecontent2 = { ... };
table2 = Table(tablecontent2);
...
Assuming 2 tables have same colomn number and definitively can adjust some other properties.
How can join them into one single table?
Thanks!

Accepted Answer

Rahul Singhal
Rahul Singhal on 13 Oct 2020
Hi John,
You can combine the cell array content and then create the DOM Table:
import mlreportgen.dom.*
tablecontent1 = { ... };
...
tablecontent2 = { ... };
...
% Combine the table content cell arrays and then create DOM Table
tableContent = [tablecontent1; tablecontent2];
table = Table(tableContent);
...
Thanks,
Rahul
  2 Comments
John
John on 13 Oct 2020
Hi, Rahul:
That was the issue. Because the Tables were made in different places and with lots of operations.If combining the cell array, it will requires complete recoding for all. That's why we seek whether if the 2 Tables can be joined together as DOM Tables.
Thanks.
John
Rahul Singhal
Rahul Singhal on 14 Oct 2020
Hi John,
In this case, you can merge the DOM tables as shown below:
import mlreportgen.dom.*
tablecontent1 = { ... };
table1 = Table(tablecontent1);
...
tablecontent2 = { ... };
table2 = Table(tablecontent2);
...
% First create a copy of the first table.
% This will make sure that the new "mergedTable" has all the content of table1.
mergedTable = clone(table1);
% Now add second table content to the "mergedTable".
% This is done by adding a copy of each row of second table to the "mergedTable".
for i=1:length(table2.Children)
row = table2.Children(i);
append(mergedTable,clone(row));
end
Thanks,
Rahul

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!