How to generate 500 permutations of any vector length 20? I am getting error

1 visualización (últimos 30 días)
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..

Respuesta aceptada

Jos (10584)
Jos (10584) el 3 de Mzo. de 2016
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 comentarios
Triveni
Triveni el 3 de Mzo. de 2016
Editada: Triveni el 4 de Mzo. de 2016
I have to generate atleast 500 permutations....can i call Y_permuted for 50 times and store generated value??
Jos (10584)
Jos (10584) el 4 de Mzo. de 2016
No, change N. Each row of Y_permuted will hold a specific permutation.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by