Reputation: 11
I have two vectors in MATLAB:
a = [1; 2; 3]
b = [4; 5; 6; 7]
I want to create a vector c
as shown below, but I can't figure out how to do it.
c = [1 2 3 4 5 6 7]
Upvotes: 0
Views: 319
Reputation: 25232
If you are not sure whether your input vectors are vertical or not, use this robust way:
c = [ a(:); b(:) ];
The colon
will make a column vector out of every vector, row AND column vectors. So you can concatenate them by [ ... ; ... ]
. If you want a row vector at the end, you need to transpose
the final result:
c = [ a(:); b(:) ].';
Upvotes: 2