MATLAB: How to display two separate tables with 2 column headings the same side-by-side
MATLABside by sidetable
I need to display two separate tables side by side with different row lengths and both tables have the same column headings.
Please see the expected table for how the data should look like.
Thank you in advance
Best Answer
First you need to pad the shorter table so it matches the same number of rows as the longer table. The two decisions you need to make are 1) what value should be used as a pad and 2) where should the padded rows be added - to the end, beginning, at certain rows, etc. This demo pads table 2 with NaN values at the end of the table.
% Create demo data, T2 has less rows than T1; both have same headers.
To concatenate both tables with the same headers side-by-side, you can use mergevars() (requires Matlab release >=r2018a) along with the MergeAsTable option to create two sub-tables. I named the two super-tables Table_1 and Table_2.
T3 = [mergevars(T1,T1.Properties.VariableNames,'NewVariableName','Table_1','MergeAsTable',true),...
Best Answer