给定组合的组合,无需重复 [英] Combinations from a given set without repetition
本文介绍了给定组合的组合,无需重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的矩阵定义如下
M = [C1 C2 C3 C4]
其中C是列向量 我想要一种有效的方式来生成A向量,例如
Where the C's are column vectors I want some efficient (i.e. no for loops) way of producing A vector such that
ResultVec = [C1 C2;
C1 C3;
C1 C4;
C2 C3;
C2 C4;
C3 C4]
提前谢谢!
推荐答案
这是我想出的最简单的方法:
This is the simplest way I've come up with:
n = size(M, 2);
[j, i] = ind2sub([n n], find(~triu(ones(n))));
ResultVec = M(:, [i j]);
ResultVec = reshape(ResultVec, [], 2)
这篇关于给定组合的组合,无需重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文