inserting vectors into a matrix

85 ビュー (過去 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"
  1 件のコメント
SHRI KRISHN
SHRI KRISHN 2018 年 1 月 6 日
C = [A,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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by