How can sort permutations.

1 次查看(过去 30 天)
Please help me to solve it
A=[30 30 30 30 30 30 60 60 60 60 60 60 60 60 30 30 30 30 30 30];
[c,b] = hist(A,unique(A));
N= length(A);
x = permn(b,N); %function permn
I have matrix A. i want to sort x. i need c(1,1) no of angle of 30. and c(1,2) no of angle of 60. means i need 12 nos of 30 and 8 nos of 60 in every permutations. How can i do it...please help me. Just like perms command works. but it's limited to 10. i need 20.
I also have another program but it's only works with 0 and 1.
A=[1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1];
n2 = numel(A);
b2 = nnz(A);
M2 = 0:ones(1,n2)*pow2(n2-1:-1:0)';
z2 = rem(floor(M2(:)*pow2(1-n2:0)),2);
out = z2(sum(z2,2) == b2,:);

采纳的回答

Andrei Bobrov
Andrei Bobrov 2015-11-1
A=[30 30 30 30 30 30 60 60 60 60 60 60 60 60 30 30 30 30 30 30];
A1 = A;
A = A1 > 30;
n2 = numel(A);
b2 = nnz(A);
M2 = 0:ones(1,n2)*pow2(n2-1:-1:0)';
z2 = rem(floor(M2(:)*pow2(1-n2:0)),2);
ii = z2(sum(z2,2) == b2,:);
aa = [30 60];
out = aa(ii + 1);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by