Fastest solution to list all pairs of n integers?

后端 未结 1 1343
小蘑菇
小蘑菇 2020-12-21 07:26

I want to list all possible pairs of the integers [1, n] with a large n. I find myself looking for the fastest option. This is what I\'ve come up w

1条回答
  •  自闭症患者
    2020-12-21 07:58

    To replace nchoosek(1:N,2)

    With bsxfun -

    [Y,X] = find(bsxfun(@gt,[1:N]',[1:N]))
    pair = [X, Y];
    

    With tril and find only (without ind2sub) -

    [y,x] = find(tril(true(N),-1))
    pair = [X, Y];
    

    0 讨论(0)
提交回复
热议问题