How to insert a matrix to another matrix ?

i have a 5 by 1 matrix A=[1,2,3,4,5] Now there is another matrix B say 5 by 5 matrix. i want matrix A to insert into matrix B such that matrix A's 1st column still has the values 1,2,3,4,5 and the rest of the columns will have the values of matrix B.
Thanks in advance

回答 (3 件)

Neil Caithness
Neil Caithness 2013 年 10 月 24 日

1 投票

A = [1,2,3,4,5];
B = randi(5,5);
Your A is a row vector, not a column. You can use transpose A'
C = [A' B]
C =
1 3 4 3 5 1
2 1 5 1 3 1
3 3 4 2 5 4
4 5 4 2 4 3
5 1 2 2 2 5
ES
ES 2013 年 10 月 24 日

0 投票

Your question is little unclear. If you want Matrix B's first column replaced by A then,
A is 5X1 B is 5X5
B=[A B(:,2:end)]
Andrei Bobrov
Andrei Bobrov 2013 年 10 月 24 日

0 投票

A = (1:5)'
B = randi(25,5);
B(:,1) = A;

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2013 年 10 月 24 日

回答済み:

2013 年 10 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by