在Matlab中创建所有可能的行组合 [英] Creating all possible combination of rows in matlab
本文介绍了在Matlab中创建所有可能的行组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个9x10000大小的矩阵.
I have a matrix which is 9x10000 size.
所以行是R1,R2到R9.
So rows are R1, R2, upto R9.
我想生成所有可能的行组合,例如[R1; R2] [R1; R3] .. [R1; R9][R1; R2; R3] ... [R1; R2; R4] ... [R1; R2:R3; R4; .. R8]
I want to generate all possible combination of the rows such as [R1;R2] [R1;R3].. [R1;R9] [R1;R2;R3]...[R1;R2;R4]... [R1;R2:R3;R4;..R8]
我目前正在使用for循环.
I am currently doing this using for loops.
有没有更好的方法呢?
推荐答案
基本上,将二进制数从1计数到2 ^ 9-i表示需要选择哪些行:
Basically, counting up the binary from 1 to 2^9-i indicates which rows need to be selected:
M=... your matrix
S=dec2bin(1:2^size(M,1)-1)=='1';
allSubsets=cell(size(S,1),1);
for ix=1:size(S,1)
allSubsets{ix}=M(find(S(ix,:)),:);
end
这篇关于在Matlab中创建所有可能的行组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文