Overlaying several matrices diagonally to create a larger matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Edvardas
el 10 de Nov. de 2014
Hello,
I am currently struggling to figure a way out to connect around 10-12 8x8 matrices diagonally in a way as shown in this image
Where essentially the corner 4x4 from the 8x8 matrix would be overlayed diagonally. Everything else in the final matrix is to be zero.
Hence was wondering if anyone has any experience of forming matrices like this and perhaps would be able to help.
So far the only solution I have figured out is basically this:
% 8x8 matrix
m = (miu*l/420).*[156 0 0 22*l 54 0 0 -13*l;...
0 156 -22*l 0 0 54 13*l 0;...
0 -22*l 4*l^2 0 0 -13*l -3*l^2 0;...
22*l 0 0 4*l^2 13*l 0 0 -3*l^2;...
54 0 0 13*l 156 0 0 -22*l;...
0 54 -13*l 0 0 156 22*l 0;...
0 13*l -3*l^2 0 0 22*l 4*l^2 0;...
-13*l 0 0 -3*l^2 -22*l 0 0 4*l^2];
%miu and l varies, so m = m1; m2 m3... etc.
%create large matrix of zeros
M=zeros(52);
M(1:8,1:8)=m1;
M(5:12, 5:12) = m2;
M(9:16, 9:16) = m3;
M(13:20, 13:20) = m4;
M(17:24, 17:24) = m5;
M(21:28, 21:28) = m6;
M(25:32, 25:32) = m7;
M(29:36, 29:36) = m8;
M(33:40, 33:40) = m9;
M(37:44, 37:44) = m10;
M(41:48, 41:48) = m11;
M(45:52, 45:52) = m12;
Which I think is a very crude solution and for large matrices is not feasible, was thinking of somehow introducing a loop to do it automatically (in which case would also need to figure how to calculate the necessary size for the zeros matrix). So yeah, perhaps someone will know a trick or two.
Kind regards, Edvardas
Respuesta aceptada
Orion
el 10 de Nov. de 2014
Editada: Orion
el 10 de Nov. de 2014
% Assuming all your m1,m2,...,m12 variables exist and are size 8x8
NumberOfSubMat = 12;
% Initialize M
M=zeros(4+4*NumberOfSubMat);
for i = 1:NumberOfSubMat
index = (1:8)+4*(i-1);
M(index,index) = eval(['m' num2str(i)]);
end
Note : the use of eval is not optimized.
Instead of createing a lot of data m1,...,m100, you should create a cell array, which component being your varying 8x8 array.
m{1} = (miu*l/420).*[156 0 0 22*l 54 0 0 -13*l;...
0 156 -22*l 0 0 54 13*l 0;...
0 -22*l 4*l^2 0 0 -13*l -3*l^2 0;...
22*l 0 0 4*l^2 13*l 0 0 -3*l^2;...
54 0 0 13*l 156 0 0 -22*l;...
0 54 -13*l 0 0 156 22*l 0;...
0 13*l -3*l^2 0 0 22*l 4*l^2 0;...
-13*l 0 0 -3*l^2 -22*l 0 0 4*l^2];
m{2} = ...
m{12} = ...
and so, you can do a cleaner loop
for i = 1:NumberOfSubMat
index = (1:8)+4*(i-1);
M(index,index) = m{i};
end
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!