how to add two tables in matlab

To add two tables in Matlab, you can use "vertcat" or "horzcat" function based on whether you want to concatenate the tables vertically or horizontally.

Syntax for "vertcat" function is:

main.m
newTable = vertcat(Table1, Table2);
36 chars
2 lines

Syntax for "horzcat" function is:

main.m
newTable = horzcat(Table1, Table2);
36 chars
2 lines

Here, Table1 and Table2 are the tables that you want to concatenate.

For example, let's say you have two tables T1 and T2 with the same number of columns and want to vertically concatenate them:

main.m
T1 = table('A', 'B', 'C', 'RowNames', {'R1'});
T2 = table(1, 2, 3, 'RowNames', {'R2'});

newTable = vertcat(T1, T2);
117 chars
5 lines

This will result in the following table:

main.m
        Var1    Var2    Var3
        ____    ____    ____
    R1  'A'     'B'     'C' 
    R2   1       2       3  
116 chars
5 lines

Similarly, for horizontal concatenation, you can use 'horzcat' function.

related categories

gistlibby LogSnag