Generate a matrix of combinations without repetition (array exceeds maximum array size preference)
显示 更早的评论
Hey,
I am trying to generate a matrix, that has all unique combinations of [0 0 1 1], I wrote this code for this:
v1 = [0 0 1 1];
M1 = unique(perms([0 0 1 1]),'rows');
This isn't ideal, because perms() is seeing each vector element as unique and doing 4! = 4 * 3 * 2 * 1 = 24 combinations.
With unique() I tried to delete all the repetitive entries so I end up with the combination matrix M1 -> only [4!/ 2! * (4-2)!] = 6 combinations!
Now, when I try to do something very simple like:
n = 15;
i = 1;
v1 = [zeros(1,n-i) ones(1,i)];
M = unique(perms(vec_1),'rows');
Instead of getting [15!/ 1! * (15-1)!] = 15 combinations, the perms() function is trying to do 15! = 1.3077e+12 combinations and it's interrupted.
How would you go about doing in a much better way? Thanks in advance!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!