我想做的是在Matlab中以最简单的方式完成以下工作
假设我们有两个数组{1,2,3} {4,5,6}。
这个算法应该会给我所有的双射:
1-4 2-5 3-6 / 1-4 2-6 3-5 / 1-5 2-4 3-6 / 1-5 2-6 3-4 / 1-6 2-5 3-4 / 1-6 2-4 3-5
发布于 2012-05-04 15:28:48
按照trutheality和repmat的建议,使用perms创建3D矩阵,以复制第一个矩阵:
x = [1 2 3];
y = [4 5 6];
Y = perms(y);
X = repmat(x,length(perms(y)),1);
Result = cat(3,X,Y);
NicerResult = permute(Result, [2, 3, 1]);
发布于 2012-05-04 06:20:03
这相当于获得第二个数组的所有排列,有一个非常方便的函数perms
。
https://stackoverflow.com/questions/10440054
复制相似问题