Our professor calls this the connectivity array (but not referring to Matlab)

3 views (last 30 days)
The goal is to combine a 3x3 matrix in a way that it becomes an 11x11 matrix. It'll be done such that the 3x3 matrix will repeat diagonally, for example if 3x3 matrix is [F G H ;
G I J;
H J F]
Then the 11x11 matrix should look like this:
[F G H 0 0 0 0 0 0 0 0;
G I J 0 0 0 0 0 0 0 0;
H J 2*F G H 0 0 0 0 0 0;
0 0 G I J 0 0 0 0 0 0;
0 0 H J 2*F G H 0 0 0 0;
0 0 0 0 G I J 0 0 0 0;
0 0 0 0 H J 2*F G H 0 0 0 0;
0 0 0 0 0 0 G I J 0 0;
0 0 0 0 0 0 H J 2*F G H;
0 0 0 0 0 0 0 0 G I J;
0 0 0 0 0 0 0 0 H J F]
notice the addition of F as a "connectivity array"
I have tried some stuff but nothing seems to work except for typing it manually and this becomes a problem if my base matrix (in this case 3x3) becomes a 10x10 or anything greater than 3x3

Answers (1)

Chunru
Chunru on 23 Sep 2022
% [F G H ;
% G I J;
% H J F]
% Then the 11x11 matrix should look like this:
% [F G H 0 0 0 0 0 0 0 0;
% G I J 0 0 0 0 0 0 0 0;
% H J 2F G H 0 0 0 0 0 0;
% 0 0 G I J 0 0 0 0 0 0;
% 0 0 H J 2F G H 0 0 0 0;
% 0 0 0 0 G I J 0 0 0 0;
% 0 0 0 0 H J 2F G H 0 0;
% 0 0 0 0 0 0 G I J 0 0;
% 0 0 0 0 0 0 H J 2F G H;
% 0 0 0 0 0 0 0 0 G I J;
% 0 0 0 0 0 0 0 0 H J F]
F = 1; G = 2; H = 3; I = 4; J = 5;
A = [F G H ; G I J; H J F]
A = 3×3
1 2 3 2 4 5 3 5 1
B = zeros(11, 11);
for i=0:4
B(i*2+(1:3), i*2+(1:3)) = B(i*2+(1:3), i*2+(1:3)) + A;
end
B
B = 11×11
1 2 3 0 0 0 0 0 0 0 0 2 4 5 0 0 0 0 0 0 0 0 3 5 2 2 3 0 0 0 0 0 0 0 0 2 4 5 0 0 0 0 0 0 0 0 3 5 2 2 3 0 0 0 0 0 0 0 0 2 4 5 0 0 0 0 0 0 0 0 3 5 2 2 3 0 0 0 0 0 0 0 0 2 4 5 0 0 0 0 0 0 0 0 3 5 2 2 3 0 0 0 0 0 0 0 0 2 4 5

Community Treasure Hunt

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

Start Hunting!