Randomly remove percentage of values above mean in array

5 visualizaciones (últimos 30 días)
j bar
j bar el 20 de Abr. de 2021
Editada: Jonas el 21 de Abr. de 2021
Say I have an array containing a set of values. How can I randomly remove 20% of the values ABOVE the mean while keeping the order the same?
Right now I have the following code completed, but this only returns an array containing 80% of the values above than the mean, I would like to have an array containing both the original data that is BELOW the mean AND the array containing 80% of the values above than the mean. In theory, this should result in randomly removing 20% of the values above the mean, however, I just can't figure out how to implement it. Any help is appreciated. I'm open to other ways of implementing this as well.
A = [set of values];
index1 = find(A>mean(A));
A_mod = A(index1);
[A_rem, idx_mod] = datasample(A_mod,round(0.80*length(A)));
  1 comentario
Jonas
Jonas el 20 de Abr. de 2021
Editada: Jonas el 21 de Abr. de 2021
looks good but you have to set the replace option in datasample to false, otherwise you would eventually remove the same same index multiple times. and you have to remove 20% not 80% of your data

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 20 de Abr. de 2021
Editada: Matt J el 20 de Abr. de 2021
A = [set of values];
A_rem=A;
index1 = find(A>mean(A)); N=numel(index1);
index2 = index1( randi(N,1,round(0.2*N)) );
A_rem(index2)=[];

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by