Combinations from a given set without repetition

前端 未结 2 1982
心在旅途
心在旅途 2020-12-21 05:21

Suppose I have a matrix defined as follows

M = [C1 C2 C3 C4]

Where the C\'s are column vectors I want some efficient (i.e. no for loops) wa

2条回答
  •  无人及你
    2020-12-21 05:30

    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)
    

提交回复
热议问题