简体   繁体   English

Matlab:如何从2个向量中找到所有可能的组合?

[英]Matlab: How to find all possible combinations from 2 vectors?

V1 and V2 are vectors 1x20 and 1x10 respectively. V1V2分别是向量1x201x10

How to find all possible combinations of 15 elements from V1 and 3 elements from V2 ? 如何找到V1中15个元素和V2 3个元素的所有可能组合?

The order of the selected elements is not important. 所选元素的顺序并不重要。

Here is one way: 这是一种方法:

% n-choose-k from each vector
A = nchoosek(1:20,15);
B = nchoosek(1:10,3);

% all combinations from the two sets
[X,Y] = ndgrid(1:size(A,1), 1:size(B,1));
C = [A(X(:),:) B(Y(:),:)];

The result contains the indices from the two vectors V1 and V2: 结果包含两个向量V1和V2的索引:

>> whos C
  Name            Size                Bytes  Class     Attributes

  C         1860480x18            267909120  double    

If you want to directly apply it to the actual vectors, replace the first two lines with: 如果要直接将其应用于实际矢量,则将前两行替换为:

A = nchoosek(V1,15);    % V1 is a 1x20 vector
B = nchoosek(V2,3);     % V2 is a 1x10 vector

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 MATLAB 中为矩阵的列向量生成所有可能的组合? - How to generate all possible combinations for the column vectors of a matrix, in MATLAB? 如何在 matlab 中找到具有这种组织的两个向量之间的所有可能交集 - how to find all the possible intersections between two vectors with such organization in matlab 在matlab中找到所有可能的组合求和 - Find all possible combinations to a sum in matlab MATLAB:如何在输入向量的所有可能组合上评估具有多个输入的函数 - MATLAB: How to evaluate a function with multiple inputs on all possible combinations of input vectors 如何在MATLAB中计算两个1x6向量的所有可能组合? - How can I calculate all of the possible combinations of two 1x6 vectors in MATLAB? MATLAB:矢量和的所有组合 - MATLAB: All combinations of sum of vectors 对于单元格A的每个向量,如何查找单元格B的向量中不包含的所有可能组成部分的组合? - For each vector of the cell A, How to find all possible combinations of its components that are not contained in vectors of the cell B? 如何计算Matlab中由数字-1和1组成的长度为6的向量的所有组合? - How to Compute All Combinations of Vectors of Length 6 Made up of Numbers -1 and 1 in Matlab? 如何从两个向量的元素的所有可能组合中获得单个数组? - How do I obtain a single array from all possible combinations of the elements of two vectors? 如何在特定条件下生成n个向量的所有可能组合 - How to generate all possible combinations of n vectors following a particular condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM