How to remove particular value from matrix?
Afficher commentaires plus anciens
I have 2*104 matrices ,I'm interested to remove all values below a particular value say 2.5E-4 from row 2?
9 commentaires
Adam
le 6 Août 2019
What do you want to end up with? Do you still want your matrix structure? If so you have to replace the values with something, e.g. NaN. You can't simply remove values entirely from a matrix and still have a matrix. If you do this your values will just be collapsed into a vector.
e.g.
myMatrix( 2, myMatrix( 2,: ) < 2.5e-4 ) = NaN;
would replace the values with NaN
Ramesh Bala
le 6 Août 2019
Ramesh Bala
le 6 Août 2019
Adam
le 6 Août 2019
So my suggested code should do this and put NaNs in there. You can put any value you want in instead of NaN, but it has to be some value and cannot be [].
Ramesh Bala
le 6 Août 2019
Adam
le 6 Août 2019
It helps if you can state what you want as clearly as possible in your question.
If you want to remove the whole column where row 2 meets that condition then:
peaks( :, peaks(2,:) < 2.5e-4 ) = [];
should do this.
As far as I can see only the 1st column has a value in the 2nd row that is less than your threshold.
So if you want to remove peaks(2,2) then I don't know what your condition is for doing this, but it isn't the one you originally stated. You can use <= and, in this case, that would also remove peaks(2,2), but comparing floating point values with equality is not a robust method. You would be better with something like
peaks( :, peaks(2,:) < 2.5e-4 + tol ) = [];
where you have defined tol as some small tolerance above 2.5e-4 that you want to include as effectively being equal to 2.5e-4.
Ramesh Bala
le 6 Août 2019
Adam
le 6 Août 2019
But peaks(2,2) is not below 2.5e-4.
Ramesh Bala
le 6 Août 2019
Réponses (0)
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!