How Can I randomly select 10% of my array values and replace it with N/A or zero

13 vues (au cours des 30 derniers jours)
Hello Everyone, I hope you are doing well.
I have the dataset 250x1000 attached below. i want to randomly select 10% of element from may array and replace it with N/A or zero. How can i do that in matlab
Any help appreciated :)

Réponse acceptée

KSSV
KSSV le 26 Fév 2022
Modifié(e) : KSSV le 26 Fév 2022
Let A be your 250x1000 array.
N = numel(A) ; % total number of elements
idx = randsample(N,round(10/100*N)) ; % select 10% of indices randomly
A(idx) = 0; % replace with 0
  6 commentaires
KSSV
KSSV le 26 Fév 2022
It is straight forward, use NaN instead of zeros. Simple.
A(idx) = NaN ; % replace with NaN
KSSV
KSSV le 26 Fév 2022
Read doc, runt he function and you can see the difference.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by