how to define an extended matrix in matlab

In MATLAB, you can define an extended matrix by concatenating two or more matrices horizontally or vertically using the square bracket notation. To concatenate two matrices horizontally, use the command horzcat. To concatenate two matrices vertically, use the command vertcat.

Here is the syntax to define an extended matrix by concatenating three matrices horizontally:

main.m
A = [1 2; 3 4];
B = [5 6; 7 8];
C = [9 10; 11 12];
D = horzcat(A, B, C);
73 chars
5 lines

And here is the syntax to define an extended matrix by concatenating two matrices vertically:

main.m
A = [1 2; 3 4];
B = [5 6; 7 8];
C = vertcat(A, B);
51 chars
4 lines

You can use the same commands to concatenate more than two matrices as well.

gistlibby LogSnag