필터 지우기
필터 지우기

Replace part of matrix with other matrix.

조회 수: 6 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by