Borrar filtros
Borrar filtros

Delete values in the array

6 visualizaciones (últimos 30 días)
Conrado Dias
Conrado Dias el 11 de Abr. de 2015
Editada: Stephen23 el 13 de Abr. de 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.

Respuesta aceptada

Stephen23
Stephen23 el 11 de Abr. de 2015
Editada: Stephen23 el 13 de Abr. de 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 comentario
Conrado Dias
Conrado Dias el 13 de Abr. de 2015
Thank you, was of great help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by