Effacer les filtres
Effacer les filtres

Delete values in the array

6 vues (au cours des 30 derniers jours)
Conrado Dias
Conrado Dias le 11 Avr 2015
Modifié(e) : Stephen23 le 13 Avr 2015
I'm having trouble developing a script. The problem:
In a matrix with positive and negative numbers, delete the values "greater and equal" and "smaller and equal" a certain value. Example:
Delete values above 100 and below -100
if anyone can help.
Thanks.

Réponse acceptée

Stephen23
Stephen23 le 11 Avr 2015
Modifié(e) : Stephen23 le 13 Avr 2015
Deleting single elements from a matrix does not really make much sense. Lets have a look at a simple case:
>> A = [1,2;3,101;4,5]
A =
1 2
3 101
4 5
If we try to delete the element > 100, then we end up with something that is not a matrix, and cannot be stored in MATLAB:
1 2
3 <- what happens here?
4 5
So what can we do instead of creating that empty space? The answer is one of two things:
1. Replace the value with another value, e.g. zero or NaN:
>> A(A>100) = NaN
A =
1 2
3 NaN
4 5
2. Delete an entire row or column, e.g. here I delete the whole second row:
>> X = any(A>100,2)
X =
0
1
0
>> A(X,:) = []
A =
1 2
4 5
  1 commentaire
Conrado Dias
Conrado Dias le 13 Avr 2015
Thank you, was of great help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by