concatenate input in matlab

To concatenate two or more inputs in MATLAB, you can use the square bracket notation [].

Example:

main.m
a = [1 2 3];
b = [4 5 6];
c = [a b] % concatenate a and b horizontally
71 chars
4 lines

Output:

main.m
c = 
     1     2     3     4     5     6
42 chars
3 lines

You can also concatenate inputs vertically by separating them with semicolons.

main.m
d = [a; b] % concatenate a and b vertically
44 chars
2 lines

Output:

main.m
d =
     1     2     3
     4     5     6
42 chars
4 lines

related categories

gistlibby LogSnag