1- 在编辑之前回答您的问题(有 n x n 个块,每个块有 n x n 个条目):
n = 3;
example = [1 2 3; 4 5 6; 7 8 9];
matrices = cat(3, example, 10*example, 100*example);
%// This is the list. Each third-dim slice is a matrix
[aux{1:n}] = deal(ones(n));
nz = ~blkdiag(aux{:}); %// template for filling result matrix
m = size(matrices,3); %// number of matrices in list
T = n^2; %// size of result matrix
N = n*(n-1); %// number of blocks
for ii = 0:m^N-1 %// number of results
ind = dec2base(ii,m,N)-'0'+1; %// indices of matrices to be used
result = zeros(T); %// initiallize to zeros
result(nz) = permute(reshape(matrices(:,:,ind),[n n n-1 n]),[1 3 2 4]);
%// fill in matrices given by ind
disp(result)
end
在这个例子中,我使用了一个包含 3 个矩阵的列表,n 是 3。所以有 729 个结果。以下是前几个:
0 0 0 1 2 3 1 2 3
0 0 0 4 5 6 4 5 6
0 0 0 7 8 9 7 8 9
1 2 3 0 0 0 1 2 3
4 5 6 0 0 0 4 5 6
7 8 9 0 0 0 7 8 9
1 2 3 1 2 3 0 0 0
4 5 6 4 5 6 0 0 0
7 8 9 7 8 9 0 0 0
0 0 0 1 2 3 1 2 3
0 0 0 4 5 6 4 5 6
0 0 0 7 8 9 7 8 9
1 2 3 0 0 0 10 20 30
4 5 6 0 0 0 40 50 60
7 8 9 0 0 0 70 80 90
1 2 3 1 2 3 0 0 0
4 5 6 4 5 6 0 0 0
7 8 9 7 8 9 0 0 0
0 0 0 1 2 3 1 2 3
0 0 0 4 5 6 4 5 6
0 0 0 7 8 9 7 8 9
1 2 3 0 0 0 100 200 300
4 5 6 0 0 0 400 500 600
7 8 9 0 0 0 700 800 900
1 2 3 1 2 3 0 0 0
4 5 6 4 5 6 0 0 0
7 8 9 7 8 9 0 0 0
0 0 0 1 2 3 10 20 30
0 0 0 4 5 6 40 50 60
0 0 0 7 8 9 70 80 90
1 2 3 0 0 0 1 2 3
4 5 6 0 0 0 4 5 6
7 8 9 0 0 0 7 8 9
1 2 3 1 2 3 0 0 0
4 5 6 4 5 6 0 0 0
7 8 9 7 8 9 0 0 0
0 0 0 1 2 3 10 20 30
0 0 0 4 5 6 40 50 60
0 0 0 7 8 9 70 80 90
1 2 3 0 0 0 10 20 30
4 5 6 0 0 0 40 50 60
7 8 9 0 0 0 70 80 90
1 2 3 1 2 3 0 0 0
4 5 6 4 5 6 0 0 0
7 8 9 7 8 9 0 0 0
2- 修改以回答您的问题编辑后(有 (n+1) x (n+1) 个块,每个块有 n x n 个条目):强>
根据您的编辑,块的数量现在更大。在这种情况下,我使用n=2 的示例。
n = 2;
matrices = cat(3, [1 2; 3 4], [10 20; 30 40], [100 200; 300 400]);
%// This is the list. Each third-dim slice is a matrix
[aux{1:n+1}] = deal(ones(n));
nz = ~blkdiag(aux{:}); %// template for filling result matrix
m = size(matrices,3); %// number of matrices in list
T = n*(n+1); %// size of result matrix
N = (n+1)*n; %// number of blocks
R = m^N; %// number of results
for ii = 0:R-1
ind = dec2base(ii,m,N)-'0'+1; %// indices of matrices to be used
result = zeros(T); %// initiallize to zeros
result(nz) = permute(reshape(matrices(:,:,ind),[n n n n+1]),[1 3 2 4]);
%// fill in matrices given by ind
disp(result)
end
前几个结果:
0 0 1 2 1 2
0 0 3 4 3 4
1 2 0 0 1 2
3 4 0 0 3 4
1 2 1 2 0 0
3 4 3 4 0 0
0 0 1 2 1 2
0 0 3 4 3 4
1 2 0 0 10 20
3 4 0 0 30 40
1 2 1 2 0 0
3 4 3 4 0 0
0 0 1 2 1 2
0 0 3 4 3 4
1 2 0 0 100 200
3 4 0 0 300 400
1 2 1 2 0 0
3 4 3 4 0 0
0 0 1 2 10 20
0 0 3 4 30 40
1 2 0 0 1 2
3 4 0 0 3 4
1 2 1 2 0 0
3 4 3 4 0 0
0 0 1 2 10 20
0 0 3 4 30 40
1 2 0 0 10 20
3 4 0 0 30 40
1 2 1 2 0 0
3 4 3 4 0 0