combining two different long and width tables to one table in matlab

You can combine two tables using the join function in MATLAB. Here's an example:

Assuming you have two tables with different number of rows:

main.m
T1 = table(rand(3,1), rand(3,1), rand(3,1), 'VariableNames', {'A', 'B', 'C'});
T2 = table(rand(4,1), rand(4,1), rand(4,1), rand(4,1), 'VariableNames', {'D', 'E', 'F', 'G'});
174 chars
3 lines

You can combine them by specifying the key variables which are the ones that will be common between the two tables. Here we'll use the row numbers as the key variable:

main.m
T_combined = join(T1, T2, 'Keys', 1:max(size(T1, 1), size(T2, 1))');
69 chars
2 lines

This will create a new table T_combined with all the columns from T1 and T2. The results for the non-matching values will be NaN.

Note that the join function requires the Data Visualization Toolbox.

related categories

gistlibby LogSnag