필터 지우기
필터 지우기

inserting vectors into a matrix

조회 수: 80 (최근 30일)
maya
maya 2013년 2월 24일
댓글: SHRI KRISHN 2018년 1월 6일
Hi,
I am wondering of there is a way that enables me to insert a column vector in a matrix (similar to insert column in excel) without replacing any existing column. For example I have Matrix "A" which is 4x4 and I want to insert a vector "B" to be the first column of "A" in order to obtain "A" 4x5 where the 1st column of "A" is vector "B"

답변 (2개)

Jan
Jan 2013년 2월 25일
And to insert a column in the middle part:
A = rand(4, 4);
B = rand(4, 1);
C(:, [1,2,5,3,4]) = [A, B];
Not nice, but it works. Alternatively:
C = [A(:, 1:2), B, A(:, 3:4)];
  댓글 수: 1
M.Basil Alazawi
M.Basil Alazawi 2016년 10월 22일
this is to column C = [A(:, 1:2), B, A(:, 3:4)];in the case the row how method or what is change in it

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


Honglei Chen
Honglei Chen 2013년 2월 24일
If your B is a 4x1 column vector, you can simply do
A = [B A]

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by