Adding Zeros vectors within a matrix

9 ビュー (過去 30 日間)
Kevin Smith
Kevin Smith 2019 年 4 月 21 日
コメント済み: Kevin Smith 2019 年 4 月 22 日
I have a 3x3 matrix of values ex
A=[ 1 2 3;
4 5 6;
7 8 9]
I need it to add zeros at certain locations with in the matrix to make a 5x5 with zeros in the 3rd and 4th row and column ex
A2=[1 2 0 0 3;
4 5 0 0 6;
0 0 0 0 0;
0 0 0 0 0;
7 8 0 0 9]
my first attempt was concatenate but I can't figure out how to move the values correctly
newA=[A,zeros(3,2)]
newA_1=[newA;zeros(2,5)]

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 21 日
A2 = zeros(5,5);
A2([1:2, 5], [1:2, 5]) = A;
  1 件のコメント
Kevin Smith
Kevin Smith 2019 年 4 月 22 日
Thank you so much. I didn't expect that to be simple.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by