How to generate 500 permutations of any vector length 20? I am getting error
조회 수: 1 (최근 30일)
이전 댓글 표시
y = [45 45 45 45 45 45 0 0 30 30 0 0 0 0 45 45 45 45 45 45];
[count,element] = hist(y,unique(y));
N1 = 5000;
x1 = permute(randi(numel(y), [1 20 N1]),[3 2 1]);
y = y(x1);
out = y(sum([ones(size(y,1),1),diff(sort(y,2),[],2)~=0],2) >= 3,:);
I am getting wrong result...I want to present 2 numbers of 30, 6 numbers of 0 and 12 numbers of 45...in every row..
댓글 수: 0
채택된 답변
Jos (10584)
2016년 3월 3일
To generate one permutation of y you can use randperm
Y = [45 45 45 45 45 45 0 0 30 30 0 0 0 0 45 45 45 45 45 45];
R = randperm(numel(Y)) % indices into y in random order
Y_permuted = Y(R)
To generate multiple rows of indices
N = 10 ;
[~, R] = sort(rand(N,numel(Y)),2)
Y_permuted = Y(R)
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Waveform Generation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!