我有一个矩阵
My_big_matrix_=rand(21,4)
My_big_matrix_=[
1.0000 0.8147 0.0357 0.7655
2.0000 0.9058 0.8491 0.7952
3.0000 0.1270 0.9340 0.1869
4.0000 0.9134 0.6787 0.4898
5.0000 0.6324 0.7577 0.4456
6.0000 0.0975 0.7431 0.6463
7.0000 0.2785 0.3922 0.7094
8.0000 0.5469 0.6555 0.7547
9.0000 0.9575 0.1712 0.2760
10.0000 0.9649 0.7060 0.6797
11.0000 0.1576 0.0318 0.6551
12.0000 0.9706 0.2769 0.1626
13.0000 0.9572 0.0462 0.1190
14.0000 0.4854 0.0971 0.4984
15.0000 0.8003 0.8235 0.9597
16.0000 0.1419 0.6948 0.3404
17.0000 0.4218 0.3171 0.5853
18.0000 0.9157 0.9502 0.2238
19.0000 0.7922 0.0344 0.7513
20.0000 0.9595 0.4387 0.2551
21.0000 0.6557 0.3816 0.5060];
我希望获得不同的行组合以获得大小(7 * 4)的矩阵
这些组合应该是
Combination_(1,1)={1,4,7,10,13,16,19}
Combination_(1,2)={1,5,7,10,13,16,19}
Combination_(1,3)={1,6,7,10,13,16,19}
Combination_(1,4)={2,4,7,10,13,16,19}
Combination_(1,5)={2,5,7,10,13,16,19}
Combination_(1,6)={2,6,7,10,13,16,19}
Combination_(1,7)={3,4,7,10,13,16,19}
Combination_(1,8)={3,5,7,10,13,16,19}
Combination_(1,9)={3,6,7,10,13,16,19}
Combination_(1,10)={1,4,7,10,13,16,19}
Combination_(1,11)={1,5,8,10,13,16,19}
Combination_(1,12)={1,6,9,10,13,16,19}
EDITED: 在我的组合中,三行(1,2,3),(4,5,6),(7,8,9),......(19,20,21)......是组。只会有一名成员,而且不会有两名成员。所以可能的解决方案不会太高。
My_small_matrix_ having size of (7,4)
有什么想法吗?
答案 0 :(得分:1)
C = combnk(1:21,7); % C rows contains combinations
numcomb = size(C, 1);
combined = zeros(numcomb, 7, 3);
for k = 1:numcomb
combined(numcomb, :, :) = reshape(My_big_matrix(numcomb(k), :), 1, 7, 3);
end
答案 1 :(得分:1)
尝试使用以下代码将数据导入单元格数组,其中每个单元格包含来自每个组合的数据 -
%// Input
My_big_matrix_ = rand(21,4)
%// Use allcomb to generate all such combinations. This a MATLAB
%// file-exchange code, available at -
%// http://www.mathworks.in/matlabcentral/fileexchange/10064-allcomb
allcomb_out = allcomb(1:3,4:6,7:9,10:12,13:15,16:18,19:21);
t1 = reshape(allcomb_out',[],1);%//'
t2 = My_big_matrix_(t1,:);
out = mat2cell(t2,7*ones(1,size(allcomb_out,1)),4); %// Desired output
答案 2 :(得分:1)
My_big_matrix_ = rand(21,4); %// data
n = size(My_big_matrix_,1);
g = 3; %// size of a group. Assumed to divide n
m = n/g;
combs = dec2base(0:g^m-1, g)-'0'+1;
combs = bsxfun(@plus, combs, 0:g:g*(m-1));
这给出了
combs =
1 4 7 10 13 16 19
1 4 7 10 13 16 20
1 4 7 10 13 16 21
1 4 7 10 13 17 19
1 4 7 10 13 17 20
[...]
3 6 9 12 15 18 20
3 6 9 12 15 18 21
然后你的小矩阵是My_big_matrix_(combs(1,:),:)
,My_big_matrix_(combs(2,:),:)
等。