# Add new column a vector.

79 views (last 30 days)
Artyom on 12 Jul 2012
Hi everyone. I have some vector for example x=[0;0;2;2;1;0;0;2;0]. How can I add a new vector (for example y=[43;43;34;34;34]) to a second column of vector x, so it becomes x=[0;0;2;2;1;0;0;2;0 43;43;34;34;34]?
##### 2 CommentsShowHide 1 older comment
Artyom on 12 Jul 2012
I don't know the size of matrix x. On each iteration I need to add a new number in the second column.

Sign in to comment.

### Accepted Answer

Ryan on 12 Jul 2012
x = [0;0;2;2;1;0;0;2;0];
y = [43;43;34;34;34];
Combined{1} = x;
Combined{2} = y;
You need to use cells {} in order to store vectors of different sizes in one array.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (2)

Sebastian Holmqvist on 12 Jul 2012
x = [0 0 2 2 1 0 0 2 0]';
y = [43 43 34 34 34 0 0 0 0]'; % Must be of same length
You could either
cat(2, x, y)
or simply
ans = [x y]
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

Jan on 12 Jul 2012
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!