Replace part of matrix with other matrix.

6 次查看(过去 30 天)
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})

更多回答(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