Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab-nchoosek问题_Matlab_Combinations_Performance - Fatal编程技术网

Matlab-nchoosek问题

Matlab-nchoosek问题,matlab,combinations,performance,Matlab,Combinations,Performance,我的问题与Matlab有关。存在一个名为nchoosek([vector],integer)的fnct。通过使用这个函数,我想得到给定向量的所有2元素组合。(即nchoosek([1:10000,2])。这是非常缓慢的,如matlab文档中所述 问题是:“有没有更快的方法做同样的工作?” 感谢您的时间,我非常感谢您的努力。如果您只需要两种元素组合,您可以使用。请注意,小于等于N的所有两个元素组合都需要N^2值,因此如果Matlab开始分页,该过程将很慢 N = 100; [xx,yy] = nd

我的问题与Matlab有关。存在一个名为nchoosek([vector],integer)的fnct。通过使用这个函数,我想得到给定向量的所有2元素组合。(即nchoosek([1:10000,2])。这是非常缓慢的,如matlab文档中所述

问题是:“有没有更快的方法做同样的工作?”


感谢您的时间,我非常感谢您的努力。

如果您只需要两种元素组合,您可以使用。请注意,小于等于
N
的所有两个元素组合都需要
N^2
值,因此如果Matlab开始分页,该过程将很慢

N = 100;
[xx,yy] = ndgrid(1:N,1:N);
allCombinations = [xx(:),yy(:)];
请注意,该功能与此功能有很大不同。
前者返回一个包含所有可能的N^2个组合的双行向量,而后者则省略了两次相同元素的组合,以及仅更改顺序的组合。引导到(n^ 2-n)/ 2行元素。

@ CONLATION:请考虑接受有用的答案。