Add new column a vector.

조회 수: 51 (최근 30일)
Artyom
Artyom 2012년 7월 12일
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
Jan
Jan 2012년 7월 12일
"x=[0;0;2;2;1;0;0;2;0 43;43;34;34;34]" is not a valid Matlab array. What size do you want for "x"? How do you want to handle the different lengths? The result must be rectangular.
Artyom
Artyom 2012년 7월 12일
I don't know the size of matrix x. On each iteration I need to add a new number in the second column.

댓글을 달려면 로그인하십시오.

채택된 답변

Ryan
Ryan 2012년 7월 12일
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.

추가 답변 (2개)

Sebastian Holmqvist
Sebastian Holmqvist 2012년 7월 12일
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]

Jan
Jan 2012년 7월 12일

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by