Replace part of matrix with other matrix.

6 vues (au cours des 30 derniers jours)
parag gupta
parag gupta le 19 Mar 2019
Commenté : parag gupta le 19 Mar 2019
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

Réponse acceptée

Matt J
Matt J le 19 Mar 2019
Z=zeros(2);
B=B+cell2mat({Z,A,A1;A2,Z,A3;A,A1,Z})
  1 commentaire
parag gupta
parag gupta le 19 Mar 2019
MJ You Are Great!!!
Thank you very much.
: )

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by