Replace part of matrix with other matrix.

8 ビュー (過去 30 日間)
parag gupta
parag gupta 2019 年 3 月 19 日
コメント済み: parag gupta 2019 年 3 月 19 日
B = [ 2,2,0,0,0,0;2,2,0,0,0,0;0,0,2,1,0,0;0,0,3,1,0,0;0,0,0,0,2,1;0,0,0,0,3,1]
i.e B is a matrix
2 2 0 0 0 0
2 2 0 0 0 0
0 0 2 1 0 0
0 0 3 1 0 0
0 0 0 0 2 1
0 0 0 0 3 1
and
A = [2,3;1,1]
A1 = [4,5;6,7]
A2 = [14,15;16,17]
A3 = [40,50;60,70]
I want to replaces zero submatrices with A,A1,A2,A3,A,A1 so that I can get the following matrix.....
B = 2 2 2 3 4 5
2 2 1 1 6 7
4 5 2 1 4 0 5 0
14 15 3 1 6 0 70
2 3 4 5 2 1
1 1 6 7 3 1
I tried to used B(B==0)=cat(3,A,A1,A2,A3,A,A1) command but didn't get right output.
Could you please tell how to replaces zero submatrices with A,A1,A2,A3,A,A1 so that I can get B matrix as mentioned above?
Thanks

採用された回答

Matt J
Matt J 2019 年 3 月 19 日
Z=zeros(2);
B=B+cell2mat({Z,A,A1;A2,Z,A3;A,A1,Z})
  1 件のコメント
parag gupta
parag gupta 2019 年 3 月 19 日
MJ You Are Great!!!
Thank you very much.
: )

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

その他の回答 (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