How can sort permutations.

조회 수: 18 (최근 30일)
Triveni
Triveni 2015년 11월 1일
답변: Andrei Bobrov 2015년 11월 1일
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