Borrar filtros
Borrar filtros

Using randsample to randomize rows

2 visualizaciones (últimos 30 días)
Joel Schelander
Joel Schelander el 30 de Mzo. de 2021
Editada: David Hill el 30 de Mzo. de 2021
I have 36 households. I want to study combinations of households. PR represents how many households that are combined. To make other calculations
feasible, I sample the data using randsample. However, when I increase PR to 9 or more, the number of combinations become to great for me to sample like this. Can I integrate the sampling with nchoosek somehow, or is there another way?
nHousehold =36;9 or
PR=7 ; %Number of Households that are to be selected
Hcombos=nchoosek(1:nHousehold,PR); %Number of combinations
y = randsample(length(Hcombos(:,1)),2);
Hcombosnew=[];
for b=1:2
Hcombosnew=[Hcombosnew; Hcombos(y(b),:)];
end
  2 comentarios
David Hill
David Hill el 30 de Mzo. de 2021
Do you have to test all combinations or just a random sampling of the combinations?
Joel Schelander
Joel Schelander el 30 de Mzo. de 2021
Just a random sampling, since there will be too many combinations

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 30 de Mzo. de 2021
Editada: David Hill el 30 de Mzo. de 2021
You could run a loop however many times you want to generate the sampling and then make sure they are all different.
y=zeros(1e5,9);
for k=1:1e5
y(k,:)=randperm(36,9);
end
y=unique(sort(y,2),'rows');

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by