Borrar filtros
Borrar filtros

I want to delete 5% random Selected Index from array and replace zero at the end MATLAB

2 visualizaciones (últimos 30 días)
hello everyone i hope you are doing well
i have dataset of shape 1x1000, i have implemeneted the following code to delete 5% samples randomly
but output replace only first index value is saved
How can i do it in MATLAB
Please help
1x1000 but value is not saving in output
output matrix =[200 0 0 0 .......]
load('dataset1')
N = numel(dataset1) ;
percentageMP=5;
size_MP=round(percentageMP/100*N);
MPV=zeros(size(dataset1));
for i=1:length(size_MP)
MP = randsample(N,size_MP) ;
sortvalue=sort(MP);
end
Temp_series1=zeros(size(dataset1));
index=1
totallength=length(dataset1)-length(MP)
for j=1:length(totallength)
for k=1:length(MP)
if j==MPV(k)
index=index+1;
end
end
Temp_series1(j)=dataset1(index)
end

Respuesta aceptada

Matt J
Matt J el 1 de Mzo. de 2022
Editada: Matt J el 1 de Mzo. de 2022
load('dataset1')
N = numel(dataset1) ;
percentageMP=5;
size_MP=round(percentageMP/100*N);
discard=randperm(N,size_MP);
dataset1(discard)=[];
dataset1(end+1:N)=0;
  34 comentarios
Walter Roberson
Walter Roberson el 2 de Mzo. de 2022
"what the effect of randomsample instead of randperm?"
The code in randsample() was designed before Mathworks upgraded the internal randperm algorithm for the two-input case. Because of that, it has an internal "optimization" for the case where less than 1/4 of the values are being selected, with the "optimization" being based on using randi() until enough distinct random values have been generated and then randomizing their order using randperm. This is guaranteed to require at least twice as many random number generations as would be used for a Fisher-Yates shuffle, which is what randperm would use for this configuration.
Also randsample requires the Statistics Toolbox but randperm does not.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by