How to replace/delete some elements of a Matrix to a certain value

1 vue (au cours des 30 derniers jours)
hasan haider
hasan haider le 23 Oct 2019
Commenté : Steven Lord le 23 Oct 2019
Hello everyone,
I have a matrix of 2799x7 matrix and i want to delete 10% of the data points or individual cells randomly. Or replace 10% of the data sets to zero. The size of the matrix should remain the same after the operation.
  1 commentaire
Steven Lord
Steven Lord le 23 Oct 2019
You can't delete individual elements of a numeric array in MATLAB to leave "holes" in the array. Guillaume listed how to replace a certain number of elements with 0's, but depending on what you're going to do with this data afterwards replacing them with NaN or missing instead of 0 may be more useful.
Generally 0 is more likely to be a valid data value than NaN. Because of this using the missing data functions (ismissing, rmmissing, fillmissing, standardizeMissing) on your 0-filled data may remove real data that happened to be 0 before you "deleted" 10% of your data points.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 23 Oct 2019
Modifié(e) : Guillaume le 23 Oct 2019
yourmatrix(randperm(numel(yourmatrix), numel(yourmatrix) * 0.1)) = 0; %replace 1/10th of the elements chosen at random by 0
  2 commentaires
hasan haider
hasan haider le 23 Oct 2019
Its giving an error. Are you sure that there will be = ?
Guillaume
Guillaume le 23 Oct 2019
It was missing a closing bracket. Fixed now.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by