Replace part of matrix with other matrix.

6 Ansichten (letzte 30 Tage)
parag gupta
parag gupta am 19 Mär. 2019
Kommentiert: parag gupta am 19 Mär. 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

Akzeptierte Antwort

Matt J
Matt J am 19 Mär. 2019
Z=zeros(2);
B=B+cell2mat({Z,A,A1;A2,Z,A3;A,A1,Z})

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by