create new vector out of two vectors in matlab

To concatenate two vectors v1 and v2 in MATLAB, you can use the vertcat or horzcat functions to create a new vertical or horizontal vector.

For example, let's say we have two vectors v1 and v2:

main.m
v1 = [1 2 3];
v2 = [4 5 6];
28 chars
3 lines

To create a new vertical vector v3 that concatenates v1 and v2, you can use:

main.m
v3 = vertcat(v1, v2);
22 chars
2 lines

The resulting vector v3 will be:

main.m
v3 =
     1
     2
     3
     4
     5
     6
47 chars
8 lines

To create a new horizontal vector v4 that concatenates v1 and v2, you can use:

main.m
v4 = horzcat(v1, v2);
22 chars
2 lines

The resulting vector v4 will be:

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

related categories

gistlibby LogSnag