How to add a column between two columns?

12 ビュー (過去 30 日間)
Jose Grimaldo
Jose Grimaldo 2020 年 2 月 5 日
コメント済み: C'lette 2024 年 2 月 4 日
I have a matrix 3x3 and a column vector 3x1. I'm trying to add the column vector between the second and third column of the 3x3 matrix.How can i add the column to the matrix?
M1=randi([-10,20],[3,3]); % M1 is 3x3 matrix
r=[5;5;5]; % r is 3x1 vector

採用された回答

Adam Danz
Adam Danz 2020 年 2 月 5 日
編集済み: Adam Danz 2020 年 2 月 5 日
out = [M1(:,1:2), r, M1(:,3)];
  1 件のコメント
C'lette
C'lette 2024 年 2 月 4 日
I suggest a little change, just to avoid hardcoding:
out = [M1(:,1:2), r, M1(:,3:end)];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by