How can sort permutations.

1 view (last 30 days)
Triveni
Triveni on 1 Nov 2015
Answered: Andrei Bobrov on 1 Nov 2015
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,:);

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 1 Nov 2015
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);

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!