There are many ways to join elements of two arrays. For example, let’s say you have two 2-by-2 matrices A and B:
A = [1 2; 3 4];
B = [5 6; 7 8];
Then the following commands concatenate B to the end of A horizontally:
H1 = [A B]
H2 = horzcat(A,B)
H3 = cat(2,A,B)
The first argument in the cat function (2) tells it to add B as additional columns of A.
These commands concatenate B to the end of A vertically:
V1 = [A; B]
V2 = vertcat(A,B)
V3 = cat(1,A,B)
The 1 tells cat to add B as additional rows of A.
For additional concatenation examples, see: