MATLAB: All possible combinations of binary matrices

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 19:57:35

Here is an example:

%# some data to work with
sz = [4 3];
k = 6;
C = rand([sz k]);

%# coefficients [0,0,0,0,0,0] to [1,1,1,1,1,1]
p = (dec2bin(0:2^k-1) == '1');

%# generate all linear combinations with the above coefficients
for i=1:size(p,1)
    %# C(:,:,1)*p(i,1) + C(:,:,2)*p(i,2) + ... + C(:,:,k)*p(i,k)
    linComb = sum(bsxfun(@times, permute(p(i,:),[1 3 2]), C),3);

    %# do something interesting with it ...
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!